<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>SpringCloud | Cying</title><meta name="keywords" content="JavaEE"><meta name="author" content="Cying-承影"><meta name="copyright" content="Cying-承影"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="SpringCloud   一、基本理念1.1 Microservices 微服务架构是“新常态”。构建小型的、自包含的、随时可以运行的应用程序可以为代码带来极大的灵活性和弹性。Spring Boot 的许多专门构建的特性使得在生产环境中大规模地构建和运行微服务变得非常容易。别忘了，没有 Spring Cloud 放松管理和提高容错能力，任何微服务架构都是不完整的。  1.1.1 Wha">
<meta property="og:type" content="article">
<meta property="og:title" content="SpringCloud">
<meta property="og:url" content="http://cyingk.github.io/2020/05/05/SpringCloud/index.html">
<meta property="og:site_name" content="Cying">
<meta property="og:description" content="SpringCloud   一、基本理念1.1 Microservices 微服务架构是“新常态”。构建小型的、自包含的、随时可以运行的应用程序可以为代码带来极大的灵活性和弹性。Spring Boot 的许多专门构建的特性使得在生产环境中大规模地构建和运行微服务变得非常容易。别忘了，没有 Spring Cloud 放松管理和提高容错能力，任何微服务架构都是不完整的。  1.1.1 Wha">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="http://img3.imgtn.bdimg.com/it/u=1799420697,1254911040&fm=26&gp=0.jpg">
<meta property="article:published_time" content="2020-05-05T08:59:27.000Z">
<meta property="article:modified_time" content="2020-05-05T09:20:51.000Z">
<meta property="article:author" content="Cying-承影">
<meta property="article:tag" content="JavaEE">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://img3.imgtn.bdimg.com/it/u=1799420697,1254911040&fm=26&gp=0.jpg"><link rel="shortcut icon" href="/img/favicon.ico"><link rel="canonical" href="http://cyingk.github.io/2020/05/05/SpringCloud/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//www.clarity.ms"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>(function(c,l,a,r,i,t,y){
    c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
    t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
    y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "4zndahq92q");</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: 'days',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"Traditional Chinese Activated Manually","cht_to_chs":"Simplified Chinese Activated Manually","day_to_night":"Dark Mode Activated Manually","night_to_day":"Light Mode Activated Manually","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: false
};

const saveToLocal = {
  // ttl 單位是 天
  set: function setWithExpiry(key, value, ttl) {
    if (ttl === 0) return
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}

// https://stackoverflow.com/questions/16839698/jquery-getscript-alternative-in-native-javascript
const getScript = url => new Promise((resolve, reject) => {
  const script = document.createElement('script')
  script.src = url
  script.async = true
  script.onerror = reject
  script.onload = script.onreadystatechange = function() {
    const loadState = this.readyState
    if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
    script.onload = script.onreadystatechange = null
    resolve()
  }
  document.head.appendChild(script)
})</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2020-05-05 17:20:51'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = '1'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}const fontSizeVal = saveToLocal.get('global-font-size')
if (fontSizeVal !== undefined) {
  document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
}})()</script><meta name="generator" content="Hexo 5.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">Loading...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">23</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">Tags</div><div class="length-num">12</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">Categories</div><div class="length-num">3</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> Categories</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://5b0988e595225.cdn.sohucs.com/images/20190831/84729f5c5bb346208416445feb485df6.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Cying</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> Categories</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">SpringCloud</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2020-05-05T08:59:27.000Z" title="Created 2020-05-05 16:59:27">2020-05-05</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2020-05-05T09:20:51.000Z" title="Updated 2020-05-05 17:20:51">2020-05-05</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Note/">Note</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">Word count:</span><span class="word-count">12.4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">Reading time:</span><span>49min</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><html><head></head><body><h1 style="
           border:none;
           margin-bottom: 50px;
           font-family: fredoka one">
    <center>SpringCloud</center>
</h1>

<h1 id="一、基本理念"><a href="#一、基本理念" class="headerlink" title="一、基本理念"></a>一、基本理念</h1><h2 id="1-1-Microservices"><a href="#1-1-Microservices" class="headerlink" title="1.1 Microservices"></a>1.1 Microservices</h2><blockquote>
<p>微服务架构是“新常态”。构建小型的、自包含的、随时可以运行的应用程序可以为代码带来极大的灵活性和弹性。Spring Boot 的许多专门构建的特性使得在生产环境中大规模地构建和运行微服务变得非常容易。别忘了，没有 Spring Cloud 放松管理和提高容错能力，任何微服务架构都是不完整的。</p>
</blockquote>
<h3 id="1-1-1-What-is-Microservices"><a href="#1-1-1-What-is-Microservices" class="headerlink" title="1.1.1 What is Microservices"></a>1.1.1 What is Microservices</h3><blockquote>
<p>微服务是一种现代的软件开发方法，应用程序代码以可管理的小块形式交付，独立于其他块。</p>
</blockquote>
<h3 id="1-1-2-Why-Microservices"><a href="#1-1-2-Why-Microservices" class="headerlink" title="1.1.2 Why Microservices"></a>1.1.2 Why Microservices</h3><blockquote>
<p>它们的小规模和相对隔离可以带来许多额外的好处，例如更容易维护、提高生产率、更大的容错性、更好的业务协调等等。</p>
</blockquote>
<h2 id="1-2-SpringCloud"><a href="#1-2-SpringCloud" class="headerlink" title="1.2 SpringCloud"></a>1.2 SpringCloud</h2><blockquote>
<p>Spring Cloud 为开发人员提供了工具，以快速构建分布式系统中的一些常见模式（例如，配置管理，服务发现，断路器，智能路由，微代理，控制总线，一次性令牌，全局锁，领导选举，分布式会话，群集状态）。分布式系统的协调导致样板式样，并且使用Spring Cloud开发人员可以快速站起来实现这些样板的服务和应用程序。它们可以在任何分布式环境中正常工作，包括开发人员自己的笔记本电脑，裸机数据中心以及Cloud Foundry等托管平台。</p>
</blockquote>
<h3 id="1-2-1-What-is-SpringCloud"><a href="#1-2-1-What-is-SpringCloud" class="headerlink" title="1.2.1 What is SpringCloud"></a>1.2.1 What is SpringCloud</h3><blockquote>
<p>Spring Cloud 是一个微服务框架，相比 Dubbo 等 RPC 框架, <strong>Spring Cloud 提供的全套的分布式系统解决方案</strong>。对微服务基础框架 Netflix 的多个开源组件进行了封装，同时又实现了和云端平台以及和 Spring Boot 开发框架的集成。 为微服务架构开发涉及的 <strong>配置管理，服务治理，熔断机制，智能路由，微代理，控制总线，一次性 token，全局一致性锁，leader 选举，分布式session，集群状态</strong> 管理等操作提供了一种简单的开发方式。为开发者提供了快速构建 <strong>分布式系统的工具</strong>，开发者可以快速的启动服务或构建应用、同时能够快速和云平台资源进行对接。</p>
</blockquote>
<h3 id="1-2-2-Why-SpringCloud"><a href="#1-2-2-Why-SpringCloud" class="headerlink" title="1.2.2 Why SpringCloud"></a>1.2.2 Why SpringCloud</h3><blockquote>
<ul>
<li><p>Distributed/versioned configuration</p>
<p>分布式/版本化配置</p>
</li>
<li><p>Service registration and discovery</p>
<p>服务注册和发现</p>
</li>
<li><p>Routing</p>
<p>路由</p>
</li>
<li><p>Service-to-service calls</p>
<p>服务间的调用</p>
</li>
<li><p>Load balancing</p>
<p>负载均衡</p>
</li>
<li><p>Circuit Breakers</p>
<p>断路器</p>
</li>
<li><p>Global locks</p>
<p>全局锁</p>
</li>
<li><p>Leadership election and cluster state</p>
<p>领导选举和集群状态</p>
</li>
<li><p>Distributed messaging</p>
<p>分布式消息传递</p>
</li>
</ul>
</blockquote>
<h1 id="二、服务注册中心"><a href="#二、服务注册中心" class="headerlink" title="二、服务注册中心"></a>二、服务注册中心</h1><h2 id="2-1-Eureka"><a href="#2-1-Eureka" class="headerlink" title="2.1 Eureka"></a>2.1 Eureka</h2><h3 id="2-1-1-What-is-Eureka"><a href="#2-1-1-What-is-Eureka" class="headerlink" title="2.1.1 What is Eureka"></a>2.1.1 What is Eureka</h3><p><strong>官方文档</strong> <a href="https://github.com/Netflix/eureka/wiki" target="_blank" rel="noopener">链接</a></p>
<blockquote>
<p>Eureka is a REST (Representational State Transfer) based service that is primarily used in the AWS cloud for locating services for the purpose of load balancing and failover of middle-tier servers. We call this service, the Eureka Server. Eureka also comes with a Java-based client component,the Eureka Client, which makes interactions with the service much easier. The client also has a built-in load balancer that does basic round-robin load balancing. At Netflix, a much more sophisticated load balancer wraps Eureka to provide weighted load balancing based on several factors like traffic, resource usage, error conditions etc to provide superior resiliency.</p>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>是一个服务注册和发现的平台，带有负载均衡的功能，我们只要简单的配置，就能实现服务的注册，并能通过 Eureka 的客户端实时观察到相关信息，有了 Eureka，就可以将多个功能相同的微服务统一服务名，注册进 Eureka，当外界调用时，就可以通过统一的服务名实现负载均衡的调用</p>
</blockquote>
<p><strong>心跳</strong></p>
<blockquote>
<p>默认每 30 秒向已注册的服务发送一次心跳包，若能收到回复则说明该服务可用，若 90 秒没有收到该服务的心跳包则说明该服务已挂，将此服务移除。</p>
</blockquote>
<h3 id="2-1-2-Dependency"><a href="#2-1-2-Dependency" class="headerlink" title="2.1.2 Dependency"></a>2.1.2 Dependency</h3><p><strong>server</strong></p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-netflix-eureka-server<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<p><strong>client</strong></p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-netflix-eureka-client<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="2-1-3-Use"><a href="#2-1-3-Use" class="headerlink" title="2.1.3 Use"></a>2.1.3 Use</h3><ul>
<li>首先引入 2.1.2  的依赖（服务端引入服务端的，客户端引入客户端的）</li>
<li>其次在 application.yml 进行配置，参考附录 8.1 的属性，下面是常用属性</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yml</div></div><figure class="highlight yml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">eureka:</span></span><br><span class="line">  <span class="attr">instance:</span></span><br><span class="line">    <span class="attr">hostname:</span> <span class="string">{url}:{port}</span></span><br><span class="line">  <span class="attr">client:</span></span><br><span class="line">    <span class="attr">register-with-eureka:</span> <span class="literal">false</span></span><br><span class="line">    <span class="attr">fetch-registry:</span> <span class="literal">false</span></span><br><span class="line">    <span class="attr">service-url:</span></span><br><span class="line">      <span class="attr">defaultZone:</span> <span class="string">http://{url}:{port}/eureka</span></span><br></pre></td></tr></tbody></table></figure></div>

<p>比如</p>
<ul>
<li>服务端</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">7001</span></span><br><span class="line"><span class="attr">eureka:</span></span><br><span class="line">  <span class="attr">client:</span></span><br><span class="line">    <span class="attr">register-with-eureka:</span> <span class="literal">false</span> <span class="comment"># 不注册进 eureka，因为自己就是</span></span><br><span class="line">    <span class="attr">fetch-registry:</span> <span class="literal">false</span>		<span class="comment"># 同</span></span><br><span class="line">    <span class="attr">service-url:</span></span><br><span class="line">      <span class="attr">defaultZone:</span> <span class="string">http://localhost:7001/eureka</span></span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li>客户端    </li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">80</span></span><br><span class="line"><span class="attr">eureka:</span></span><br><span class="line">  <span class="attr">client:</span></span><br><span class="line">    <span class="attr">register-with-eureka:</span> <span class="literal">true</span>	<span class="comment"># 这个当然就要注册进 eureka 了</span></span><br><span class="line">    <span class="attr">fetch-registry:</span> <span class="literal">true</span>		<span class="comment"># 同</span></span><br><span class="line">    <span class="attr">service-url:</span></span><br><span class="line">      <span class="attr">defaultZone:</span> <span class="string">http://localhost:7001/eureka</span></span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li>在主启动类添加注解 <code>@EnableEurekaServer</code> 或 <code>@EnableEurekaClient</code></li>
<li>最后访问 Eureka 客户端，url 为 localhost，端口为微服务端口</li>
<li><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200428235723565.png" data-fancybox="group" data-caption="image-20200428235723565" class="fancybox"><img alt="image-20200428235723565" title="image-20200428235723565" data-src="http://narpro.top/img/image-20200428235723565.png" class="lazyload"></a></li>
</ul>
<h2 id="2-2-Zookeeper"><a href="#2-2-Zookeeper" class="headerlink" title="2.2 Zookeeper"></a>2.2 Zookeeper</h2><h3 id="2-2-1-What-is-Zookeeper"><a href="#2-2-1-What-is-Zookeeper" class="headerlink" title="2.2.1 What is Zookeeper"></a>2.2.1 What is Zookeeper</h3><p><strong>官方文档</strong></p>
<blockquote>
<p>Spring Cloud Zookeeper provides <a href="https://zookeeper.apache.org/" target="_blank" rel="noopener">Apache Zookeeper</a> integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms. With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with Zookeeper. The patterns provided include Service Discovery and Distributed Configuration.</p>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>和 Eureka 一样的，都是服务注册中心，只要简单的注解和配置就能实现服务注册和服务发现，不过 Zookeeper 并没有可视化 web 客户端，而是一个类 Linux 操作的控制台作为客户端，而且 Zookeeper 的服务器也是这种形式</p>
</blockquote>
<h3 id="2-2-2-Dependency"><a href="#2-2-2-Dependency" class="headerlink" title="2.2.2 Dependency"></a>2.2.2 Dependency</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-zookeeper-discovery<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="2-2-3-Use"><a href="#2-2-3-Use" class="headerlink" title="2.2.3 Use"></a>2.2.3 Use</h3><ul>
<li><p>配置好 Zookeeper，然后启动 Zookeeper 服务器</p>
</li>
<li><p>微服务的启动：</p>
<ul>
<li>引入 2.2.2 的依赖</li>
</ul>
</li>
<li><p>配置 application.yml</p>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">zookeeper:</span></span><br><span class="line">      <span class="attr">connect-string:</span> <span class="string">localhost:2181</span></span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li><p>启动微服务</p>
</li>
<li><p>可通过 Zookeeper 客户端查看已注册的服务</p>
</li>
</ul>
<h2 id="2-3-Consul"><a href="#2-3-Consul" class="headerlink" title="2.3 Consul"></a>2.3 Consul</h2><h3 id="2-3-1-What-is-Consul"><a href="#2-3-1-What-is-Consul" class="headerlink" title="2.3.1 What is Consul"></a>2.3.1 What is Consul</h3><p><strong>官方文档</strong> <a href="https://spring.io/projects/spring-cloud-consul" target="_blank" rel="noopener">链接</a></p>
<blockquote>
<p>Spring Cloud Consul provides <a href="https://consul.io/" target="_blank" rel="noopener">Consul</a> integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms. With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with Hashicorp’s Consul. The patterns provided include Service Discovery, Distributed Configuration and Control Bus.</p>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>同 Eureka 和 Zookeeper，不过服务器需下载，有 web 界面客户端</p>
</blockquote>
<h3 id="2-3-2-Dependency"><a href="#2-3-2-Dependency" class="headerlink" title="2.3.2 Dependency"></a>2.3.2 Dependency</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-consul-discovery<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="2-3-3-Use"><a href="#2-3-3-Use" class="headerlink" title="2.3.3 Use"></a>2.3.3 Use</h3><ul>
<li><p>首先下载 Consul，用 consul.exe agent -dev 命令启动</p>
</li>
<li><p><a href="http://localhost:8500/" target="_blank" rel="noopener">http://localhost:8500/</a> 访问一下，看有没有启动成功</p>
</li>
<li><p>微服务启动：</p>
<ul>
<li><p>首先引入 2.3.2 的依赖</p>
</li>
<li><p>配置 application.yml 文件</p>
</li>
</ul>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">consul:</span></span><br><span class="line">      <span class="attr">host:</span> <span class="string">localhost</span></span><br><span class="line">      <span class="attr">port:</span> <span class="number">8500</span></span><br><span class="line">      <span class="attr">discovery:</span></span><br><span class="line">        <span class="attr">service-name:</span> <span class="string">${spring.application.name}</span></span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li>启动</li>
</ul>
<h1 id="三、服务调用"><a href="#三、服务调用" class="headerlink" title="三、服务调用"></a>三、服务调用</h1><h2 id="3-1-Ribbon"><a href="#3-1-Ribbon" class="headerlink" title="3.1 Ribbon"></a>3.1 Ribbon</h2><h3 id="3-1-1-What-is-Ribbon"><a href="#3-1-1-What-is-Ribbon" class="headerlink" title="3.1.1 What is Ribbon"></a>3.1.1 What is Ribbon</h3><p><strong>官方文档</strong> <a href="https://github.com/Netflix/ribbon/wiki" target="_blank" rel="noopener">链接</a></p>
<blockquote>
<p>Ribbon plays a critical role in supporting inter-process communication in the cloud. The library includes the Netflix client side load balancers and clients for middle tier services.</p>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>Ribbon 用于云端微服务之间的通信，包含了 Netflix 的负载均衡器和中间层客户端，而且在前面的 Eureka 里已经使用过 Ribbon 了</p>
</blockquote>
<h3 id="3-1-2-Dependency"><a href="#3-1-2-Dependency" class="headerlink" title="3.1.2 Dependency"></a>3.1.2 Dependency</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-netflix-ribbon<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">version</span>></span>2.2.1.RELEASE<span class="tag">< /<span class="attr">version</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="3-1-3-Use"><a href="#3-1-3-Use" class="headerlink" title="3.1.3 Use"></a>3.1.3 Use</h3><ul>
<li><p>引入依赖</p>
</li>
<li><p>配置 RestTemplate 类</p>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">TemplateConfig</span> </span>{</span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="meta">@LoadBalanced</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> RestTemplate <span class="title">getRestTemplate</span><span class="params">()</span> </span>{</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> RestTemplate();</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li><p>注入 RestTemplate 对象 rt</p>
</li>
<li><p>使用 rt.getForObject() 和 rt.postForObject() 进行服务调用即可，或使用 rt.getObjectForEntity() / rt.postObjectForEntity()，后面两种更为详细，包含状态码等信息。</p>
</li>
</ul>
<p><strong>负载均衡算法</strong></p>
<blockquote>
<ul>
<li>RoundRobinRule – 轮询</li>
<li>RandomRule – 随机</li>
<li>RetryRule – 先轮询，若失败会在指定时间内重试</li>
<li>WeightedResponseTimeRule – 响应速度越快的越容易被选中</li>
<li>BestAvailableRule – 会先过滤掉因多次访问故障进入熔断状态的微服务，并选择一个并发量最小的服务</li>
<li>AvailabilityFilteringRule – 先过滤故障服务，并选择并发较小的</li>
<li>ZoneAvoidanceRule – 复合判断 server 所在区域的性能和 server 的可用性的可选择性服务器</li>
</ul>
</blockquote>
<p><strong>负载均衡切换</strong></p>
<blockquote>
<p>根据官方文档所说，该配置类不能放在 @ComponentScan 能扫描到的地方，而 @SpringBootApplication 注解自带了 @ComponentScan，所以我们的配置文件不能放在主启动的同一个包或子包下，应如下所示</p>
<p><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200501125851117.png" data-fancybox="group" data-caption="image-20200501125851117" class="fancybox"><img alt="image-20200501125851117" title="image-20200501125851117" data-src="http://narpro.top/img/image-20200501125851117.png" class="lazyload"></a></p>
<p>然后编写配置类</p>
</blockquote>
 <div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.cying.ribbon;</span><br><span class="line"><span class="keyword">import</span> com.netflix.loadbalancer.IRule;</span><br><span class="line"><span class="keyword">import</span> com.netflix.loadbalancer.RandomRule;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Bean;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Configuration;</span><br><span class="line"> <span class="meta">@Configuration</span></span><br><span class="line"> <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyRule</span> </span>{</span><br><span class="line">  <span class="meta">@Bean</span></span><br><span class="line">  <span class="function"><span class="keyword">public</span> IRule <span class="title">myRule</span><span class="params">()</span> </span>{</span><br><span class="line">      <span class="keyword">return</span> <span class="keyword">new</span> 负载均衡算法();</span><br><span class="line">  }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// 注意，Ribbon 负载均衡是用于客户端，所以该配置类也只需在客户端配置</span></span><br></pre></td></tr></tbody></table></figure></div>

<h2 id="3-2-OpenFeign"><a href="#3-2-OpenFeign" class="headerlink" title="3.2 OpenFeign"></a>3.2 OpenFeign</h2><h3 id="3-2-1-What-is-OpenFeign"><a href="#3-2-1-What-is-OpenFeign" class="headerlink" title="3.2.1 What is OpenFeign"></a>3.2.1 What is OpenFeign</h3><p><strong>官方文档</strong> <a href="https://spring.io/projects/spring-cloud-openfeign" target="_blank" rel="noopener">链接</a></p>
<blockquote>
<p>This project provides <a href="https://github.com/OpenFeign/feign" target="_blank" rel="noopener">OpenFeign</a> integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms.</p>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>在 Ribbon + RestTemplate 的基础上进一步封装，对外只需提供接口即可，更符合 SpringMVC 规范</p>
</blockquote>
<h3 id="3-2-2-Dependency"><a href="#3-2-2-Dependency" class="headerlink" title="3.2.2 Dependency"></a>3.2.2 Dependency</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-openfeign<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="3-2-3-Use"><a href="#3-2-3-Use" class="headerlink" title="3.2.3 Use"></a>3.2.3 Use</h3><ul>
<li><p>引入依赖</p>
<ul>
<li>书写主启动类，在主启动类标注 @EnableFeignClient 注解</li>
</ul>
</li>
<li><p>书写接口，在接口上标注 @Component 和 @FeignClient(value=””) 注解，value 里是要调用的服务名</p>
</li>
<li><p>接口类的方法上也需要 @GetMapping，@PostMapping 或者 @RequestMapping 注解，路径即要请求的路径。 </p>
</li>
<li><p>比如：</p>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.cying.cloud.service;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.cying.cloud.entities.CommonResult;</span><br><span class="line"><span class="keyword">import</span> com.cying.cloud.entities.Payment;</span><br><span class="line"><span class="keyword">import</span> org.springframework.cloud.openfeign.FeignClient;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.GetMapping;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.PathVariable;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@FeignClient</span>(value = <span class="string">"Consul-Payment"</span>) <span class="comment">// 这里是要请求的服务</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">PaymentService</span> </span>{</span><br><span class="line">    <span class="meta">@GetMapping</span>(<span class="string">"/c/get/{id}"</span>) <span class="comment">// 这里就是要请求的路径</span></span><br><span class="line">    <span class="function">CommonResult<payment> <span class="title">get</span><span class="params">(@PathVariable(<span class="string">"id"</span>)</span> Long id)</payment></span>;</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<p><strong>超时设置</strong></p>
<blockquote>
<p>OpenFeign 默认等待一秒，但有些业务可能一秒之内完成不了，顾需要自定义时间</p>
</blockquote>
 <div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ribbon:</span><br><span class="line">	ReadTimeout: ?	// 建立连接允许时间</span><br><span class="line">	ConnectTimeout: ?	// 得到回复允许时间</span><br></pre></td></tr></tbody></table></figure></div>

<h1 id="四、服务断路器"><a href="#四、服务断路器" class="headerlink" title="四、服务断路器"></a>四、服务断路器</h1><h2 id="4-1-Hystrix"><a href="#4-1-Hystrix" class="headerlink" title="4.1 Hystrix"></a>4.1 Hystrix</h2><h3 id="4-1-1-What-is-Hystrix"><a href="#4-1-1-What-is-Hystrix" class="headerlink" title="4.1.1 What is Hystrix"></a>4.1.1 What is Hystrix</h3><p><strong>官方文档</strong> <a href="https://github.com/Netflix/Hystrix/wiki" target="_blank" rel="noopener">链接</a></p>
<blockquote>
<p>In a distributed environment, inevitably some of the many service dependencies will fail. Hystrix is a library that helps you control the interactions between these distributed services by adding latency tolerance and fault tolerance logic. Hystrix does this by isolating points of access between the services, stopping cascading failures across them, and providing fallback options, all of which improve your system’s overall resiliency.</p>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>当微服务出现故障或者调用失败时采取一定的措施以保证整个系统的可用性。包括服务限流，服务降级，服务熔断。</p>
<ul>
<li><p>服务限流：当一个微服务的访问量突然之间变得很大时采取的措施</p>
</li>
<li><p>服务降级：当服务器忙时，不让客户端一直等待，而是返回一个友好提示</p>
<ul>
<li><strong>触发条件</strong><ul>
<li>程序运行异常时</li>
<li>超时</li>
<li>服务熔断时</li>
<li>线程池/信号量打满时 </li>
</ul>
</li>
</ul>
</li>
<li><p>服务熔断：当达到最大服务访问后，直接拒绝访问，拉闸限电，然后调用服务降级的方法并返回友好提示</p>
<ul>
<li><strong>触发条件</strong><ul>
<li>某个微服务出错，不可用或者响应时间太长</li>
</ul>
</li>
<li><strong>缺省条件</strong><ul>
<li>5s 内 20 次调用失败</li>
</ul>
</li>
<li><strong>基本原理</strong><ul>
<li>让断路器本身检测基础调用是否再次工作正常。可以通过在适当的时间间隔后再次尝试受保护的调用来实现这种自我的重置行为，并在成功后重置断路器</li>
</ul>
</li>
</ul>
<p><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200501233446496.png" data-fancybox="group" data-caption="image-20200501233446496" class="fancybox"><img alt="image-20200501233446496" title="image-20200501233446496" data-src="http://narpro.top/img/image-20200501233446496.png" class="lazyload"></a></p>
<p><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200502000553661.png" data-fancybox="group" data-caption="image-20200502000553661" class="fancybox"><img alt="image-20200502000553661" title="image-20200502000553661" data-src="http://narpro.top/img/image-20200502000553661.png" class="lazyload"></a></p>
<p><a target="_blank" rel="noopener" href="http://narpro.top/img/hystrix.png" data-fancybox="group" data-caption="image-20200502000553661" class="fancybox"><img alt="image-20200502000553661" title="image-20200502000553661" data-src="http://narpro.top/img/hystrix.png" class="lazyload"></a></p>
</li>
</ul>
</blockquote>
<h3 id="4-1-2-Dependency"><a href="#4-1-2-Dependency" class="headerlink" title="4.1.2 Dependency"></a>4.1.2 Dependency</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-netflix-hystrix<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="4-1-3-Use"><a href="#4-1-3-Use" class="headerlink" title="4.1.3 Use"></a>4.1.3 Use</h3><ul>
<li>引入 4.1.2 的依赖</li>
</ul>
<h4 id="4-1-3-1-fallback"><a href="#4-1-3-1-fallback" class="headerlink" title="4.1.3.1 fallback"></a>4.1.3.1 fallback</h4><h5 id="4-1-3-1-1-用于服务端"><a href="#4-1-3-1-1-用于服务端" class="headerlink" title="4.1.3.1.1 用于服务端"></a>4.1.3.1.1 <strong>用于服务端</strong></h5><ul>
<li>在主启动类添加 @EnableCircuitBreaker 注解</li>
<li>在需要降级的方法上添加 @HystrixCommand 注解</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping</span>(value = <span class="string">"/hs/get/{id}"</span>)</span><br><span class="line"><span class="meta">@HystrixCommand</span>(</span><br><span class="line">        fallbackMethod = <span class="string">"getEHandler"</span>, <span class="comment">// 服务降级处理方法</span></span><br><span class="line">        commandProperties = {</span><br><span class="line">                <span class="meta">@HystrixProperty</span>(name = <span class="string">"execution.isolation.thread.timeoutInMilliseconds"</span>, value = <span class="string">"4000"</span>) <span class="comment">// 限定处理时间，若超过 4 秒则进行服务降级，跳转至处理方法</span></span><br><span class="line">        }</span><br><span class="line">)</span><br><span class="line"><span class="function"><span class="keyword">public</span> CommonResult<payment> <span class="title">getE</span><span class="params">(@PathVariable(<span class="string">"id"</span>)</span> Long id) </payment></span>{</span><br><span class="line">    <span class="keyword">try</span> {</span><br><span class="line">        TimeUnit.SECONDS.sleep(<span class="number">10</span>); <span class="comment">// 模拟重量级程序，需处理十秒钟</span></span><br><span class="line">    } <span class="keyword">catch</span> (InterruptedException e) {</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    }</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<>(<span class="number">200</span>, Thread.currentThread().getStackTrace().toString(), port, service.getPaymentById(id));</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">//降级处理方法</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> CommonResult<payment> <span class="title">getEHandler</span><span class="params">(Long id)</span> </payment></span>{</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<>(<span class="number">200</span>, Thread.currentThread().getStackTrace().toString(), <span class="string">"请求超时"</span>, <span class="keyword">new</span> Payment(<span class="keyword">null</span>, <span class="keyword">null</span>));</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<h5 id="4-1-3-1-2-用于客户端"><a href="#4-1-3-1-2-用于客户端" class="headerlink" title="4.1.3.1.2 用于客户端"></a>4.1.3.1.2 <strong>用于客户端</strong></h5><ul>
<li>在主启动类添加 @EnableHystrix 注解</li>
<li>在需要降级的方法上添加 @HystrixCommand 注解</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping</span>(value = <span class="string">"/gete/{id}"</span>)</span><br><span class="line"><span class="meta">@HystrixCommand</span>(</span><br><span class="line">    fallbackMethod = <span class="string">"geteHandler"</span>, <span class="comment">// 服务降级处理方法</span></span><br><span class="line">    commandProperties = {</span><br><span class="line">        <span class="meta">@HystrixProperty</span>(name = <span class="string">"execution.isolation.thread.timeoutInMilliseconds"</span>, value = <span class="string">"1000"</span>) <span class="comment">// 限定处理时间，若超过 1 秒则进行服务降级，跳转至处理方法</span></span><br><span class="line">    }</span><br><span class="line">)</span><br><span class="line"><span class="function"><span class="keyword">public</span> CommonResult<payment> <span class="title">gete</span><span class="params">(@PathVariable(<span class="string">"id"</span>)</span> Long id) </payment></span>{</span><br><span class="line">    <span class="keyword">return</span> service.getE(id);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">//降级处理方法</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> CommonResult<payment> <span class="title">geteHandler</span><span class="params">(Long id)</span> </payment></span>{</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<>(<span class="number">200</span>, Thread.currentThread().getStackTrace().toString(), <span class="string">"这里是客户端降级处理，服务请求已超时"</span>, <span class="keyword">new</span> Payment(<span class="keyword">null</span>, <span class="keyword">null</span>));</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<h5 id="4-1-3-1-3-全局降级方法"><a href="#4-1-3-1-3-全局降级方法" class="headerlink" title="4.1.3.1.3 全局降级方法"></a>4.1.3.1.3 全局降级方法</h5><ul>
<li>在需要降级的类上写上 @DefaultProperties(defaultFallback = “方法名”) 注解</li>
<li>在需要使用全局服务降级的方法上直接写上 @HystrixCommand 注解</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@Slf</span>4j</span><br><span class="line"><span class="meta">@DefaultProperties</span>(defaultFallback = <span class="string">"myFall"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">OrderController</span> </span>{</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Resource</span></span><br><span class="line">    <span class="keyword">private</span> OrderService service;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@HystrixCommand</span>(</span><br><span class="line">            commandProperties = {</span><br><span class="line">                    <span class="meta">@HystrixProperty</span>(name = <span class="string">"execution.isolation.thread.timeoutInMilliseconds"</span>, value = <span class="string">"1000"</span>) <span class="comment">// 限定处理时间，若超过 1 秒则进行服务降级，跳转至处理方法</span></span><br><span class="line">            }</span><br><span class="line">    )</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"/geteg/{id}"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> CommonResult<payment> <span class="title">geteg</span><span class="params">(@PathVariable(<span class="string">"id"</span>)</span> Long id) </payment></span>{</span><br><span class="line">        <span class="keyword">return</span> service.getE(id);</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> CommonResult<payment> <span class="title">myFall</span><span class="params">()</span> </payment></span>{</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<>(<span class="number">200</span>, Thread.currentThread().getStackTrace().toString(), <span class="string">"全局降级方法"</span>, <span class="keyword">new</span> Payment());</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<h5 id="4-1-3-1-4-结合-OpenFeign"><a href="#4-1-3-1-4-结合-OpenFeign" class="headerlink" title="4.1.3.1.4 结合 OpenFeign"></a>4.1.3.1.4 结合 OpenFeign</h5><ul>
<li>在 application.yml 配置 feign.hystrix.enabled = true</li>
<li>新建类，实现 OpenFeign 接口，在实现的方法里写降级逻辑</li>
<li>在 OpenFeign 接口的 @FeignClient 注解中添加属性 fallback = 实现类</li>
</ul>
<h4 id="4-1-3-2-CirecuitBreaker"><a href="#4-1-3-2-CirecuitBreaker" class="headerlink" title="4.1.3.2 CirecuitBreaker"></a>4.1.3.2 CirecuitBreaker</h4><ul>
<li><p>同样，在需要熔断的方法上添加 @HystrixCommand 注解，并指定 fallbackMethod 为解决方法</p>
</li>
<li><p>添加 commandProperties 属性</p>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">commandProperties = {</span><br><span class="line">    <span class="comment">// 是否开启断路器</span></span><br><span class="line">    <span class="meta">@HystrixProperty</span>(name = <span class="string">"circuitBreaker.enabled"</span>, value = <span class="string">"true"</span>),</span><br><span class="line">    <span class="comment">// 请求次数</span></span><br><span class="line">    <span class="meta">@HystrixProperty</span>(name = <span class="string">"circuitBreaker.requestVolumeThreshold"</span>, value = <span class="string">"10"</span>),</span><br><span class="line">    <span class="comment">// 时间窗口期</span></span><br><span class="line">    <span class="meta">@HystrixProperty</span>(name = <span class="string">"circuitBreaker.sleepWindowInMilliseconds"</span>, value = <span class="string">"10000"</span>),</span><br><span class="line">    <span class="comment">// 错误率</span></span><br><span class="line">    <span class="meta">@HystrixProperty</span>(name = <span class="string">"circuitBreaker.errorThresholdPercentage"</span>, value = <span class="string">"60"</span>)</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">  * 结合起来的意思就是，当 10 秒钟内，10 次有 60% 的请求出错则开启断路器 </span></span><br><span class="line"><span class="comment">  */</span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="4-1-4-Hystrix-Dashboard"><a href="#4-1-4-Hystrix-Dashboard" class="headerlink" title="4.1.4 Hystrix Dashboard"></a>4.1.4 Hystrix Dashboard</h3><ul>
<li><p>新建 Module </p>
</li>
<li><p>引入依赖</p>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-netflix-hystrix-dashboard<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li>创建主启动类并启动</li>
</ul>
<h1 id="五、服务网关"><a href="#五、服务网关" class="headerlink" title="五、服务网关"></a>五、服务网关</h1><h2 id="5-1-Gateway"><a href="#5-1-Gateway" class="headerlink" title="5.1 Gateway"></a>5.1 Gateway</h2><h3 id="5-1-1-What-is-Gateway"><a href="#5-1-1-What-is-Gateway" class="headerlink" title="5.1.1 What is Gateway"></a>5.1.1 What is Gateway</h3><p><strong>官方文档</strong></p>
<blockquote>
<p>This project provides a library for building an API Gateway on top of Spring MVC. Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross cutting concerns to them such as: security, monitoring/metrics, and resiliency.</p>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>此 Gateway 不是你第一想到的那个 Gateway，也就是常被称作网关的 Gateway，这里的 Gateway 是 Spring 公司的产品，是网关 Gateway 理念的实现产品。追求极简的配置完成 API 的跳转，基于 webFlux 的非阻塞架构</p>
</blockquote>
<p><strong>三大特性</strong></p>
<blockquote>
<ul>
<li>Route</li>
<li>Predicate</li>
<li>Filter</li>
</ul>
</blockquote>
<p><strong>工作流程</strong></p>
<p><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200503201603217.png" data-fancybox="group" data-caption="image-20200503201603217" class="fancybox"><img alt="image-20200503201603217" title="image-20200503201603217" data-src="http://narpro.top/img/image-20200503201603217.png" class="lazyload"></a></p>
<h3 id="5-1-2-Dependency"><a href="#5-1-2-Dependency" class="headerlink" title="5.1.2 Dependency"></a>5.1.2 Dependency</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-gateway<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br><span class="line"><span class="comment"><!-- 注意，此处不需引入 web 和 acturator 依赖 --></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="5-1-3-Use"><a href="#5-1-3-Use" class="headerlink" title="5.1.3 Use"></a>5.1.3 Use</h3><h4 id="5-1-3-1-Route-amp-Predicate"><a href="#5-1-3-1-Route-amp-Predicate" class="headerlink" title="5.1.3.1 Route & Predicate"></a>5.1.3.1 Route & Predicate</h4><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">	<span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">discovery:</span> <span class="string">//</span> <span class="string">开启微服务动态路由</span></span><br><span class="line">        <span class="attr">locator:</span></span><br><span class="line">          <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line">      <span class="attr">routes:</span> <span class="string">//</span> <span class="string">配置路由</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">cp1</span> <span class="string">//</span> <span class="string">第一条的</span> <span class="string">id</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">lb://Consul-Payment</span> <span class="string">//</span> <span class="string">lb://</span> <span class="string">+</span> <span class="string">要访问的微服务名</span></span><br><span class="line">          <span class="attr">predicates:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">Path=/c/get/**</span> <span class="string">//</span> <span class="string">断言，当请求路径以</span> <span class="string">/c/get/开头才允许通过</span></span><br></pre></td></tr></tbody></table></figure></div>

<h4 id="5-1-3-2-Filter"><a href="#5-1-3-2-Filter" class="headerlink" title="5.1.3.2 Filter"></a>5.1.3.2 Filter</h4><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@Slf</span>4j</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyLogGateWayFilter</span> <span class="keyword">implements</span> <span class="title">GlobalFilter</span>,<span class="title">Ordered</span> </span>{</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Mono<void> <span class="title">filter</span><span class="params">(ServerWebExchange exchange, GatewayFilterChain chain)</span> </void></span>{</span><br><span class="line">        String uname = exchange.getRequest().getQueryParams().getFirst(<span class="string">"uname"</span>); <span class="comment">//获取第一个参数</span></span><br><span class="line">        <span class="keyword">if</span>(uname == <span class="keyword">null</span>) {</span><br><span class="line">            exchange.getResponse().setStatusCode(HttpStatus.NOT_ACCEPTABLE); <span class="comment">//设置状态码</span></span><br><span class="line">            <span class="keyword">return</span> exchange.getResponse().setComplete(); <span class="comment">//返回</span></span><br><span class="line">        }</span><br><span class="line">        <span class="keyword">return</span> chain.filter(exchange); <span class="comment">// 放行</span></span><br><span class="line">    }</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getOrder</span><span class="params">()</span> </span>{</span><br><span class="line">        <span class="keyword">return</span> <span class="number">0</span>; <span class="comment">//这个方法是设置优先级的，0 最先执行</span></span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<h4 id="5-1-3-3-CORS"><a href="#5-1-3-3-CORS" class="headerlink" title="5.1.3.3.CORS"></a>5.1.3.3.CORS</h4><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">globalcors:</span></span><br><span class="line">        <span class="attr">cors-configurations:</span></span><br><span class="line">          <span class="string">'[/**]'</span><span class="string">:</span> <span class="string">//正则表达式</span></span><br><span class="line">            <span class="attr">allow-credentials:</span> <span class="literal">true</span> <span class="string">//是否允许</span></span><br><span class="line">            <span class="attr">allowed-origins:</span> <span class="string">//允许哪些</span></span><br><span class="line">              <span class="bullet">-</span> <span class="string">"null"</span></span><br><span class="line">            <span class="attr">allowed-headers:</span> <span class="string">"*"</span> <span class="string">//允许的请求头</span></span><br><span class="line">            <span class="attr">allowed-methods:</span> <span class="string">//允许的请求方法</span></span><br><span class="line">              <span class="bullet">-</span> <span class="string">GET</span></span><br></pre></td></tr></tbody></table></figure></div>

<h1 id="六、服务配置"><a href="#六、服务配置" class="headerlink" title="六、服务配置"></a>六、服务配置</h1><h2 id="6-1-Config"><a href="#6-1-Config" class="headerlink" title="6.1 Config"></a>6.1 Config</h2><h3 id="6-1-1-What-is-Config"><a href="#6-1-1-What-is-Config" class="headerlink" title="6.1.1 What is Config"></a>6.1.1 What is Config</h3><p><strong>官方文档</strong></p>
<blockquote>
<p>Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments. The concepts on both client and server map identically to the Spring <code>Environment</code> and <code>PropertySource</code> abstractions, so they fit very well with Spring applications, but can be used with any application running in any language. As an application moves through the deployment pipeline from dev to test and into production you can manage the configuration between those environments and be certain that applications have everything they need to run when they migrate. The default implementation of the server storage backend uses git so it easily supports labelled versions of configuration environments, as well as being accessible to a wide range of tooling for managing the content. It is easy to add alternative implementations and plug them in with Spring configuration.</p>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>在工作中，我们有很多配置可能是通用的，比如数据库的配置，当数据库做了迁移，那么所有连接都要更改，会造成一定麻烦，所以这里的 config 就是为了管理全局配置而生的插件环境，通过将配置文件存放了 git 上，通过一个 config server 读取到 git 的配置，并通知其他平台更新，达到一处修改，处处生效的结果</p>
</blockquote>
<h3 id="6-1-2-Dependency"><a href="#6-1-2-Dependency" class="headerlink" title="6.1.2 Dependency"></a>6.1.2 Dependency</h3><p><strong>server</strong></p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-config-server<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<p><strong>client</strong></p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-config-client<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="6-1-3-Use"><a href="#6-1-3-Use" class="headerlink" title="6.1.3 Use"></a>6.1.3 Use</h3><ul>
<li><p>引入依赖</p>
</li>
<li><p>配置 application.yml</p>
<ul>
<li>服务端</li>
</ul>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yml</div></div><figure class="highlight yml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">config:</span></span><br><span class="line">      <span class="attr">server:</span></span><br><span class="line">        <span class="attr">git:</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">git@github.com:CyingK/springcloud-config.git</span> <span class="string">//地址</span></span><br><span class="line">          <span class="attr">search-paths:</span> </span><br><span class="line">            <span class="bullet">-</span> <span class="string">springcloud-config</span> <span class="string">//路径</span></span><br><span class="line">      <span class="attr">label:</span> <span class="string">master</span> <span class="string">//分支</span></span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li>客户端</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">config:</span></span><br><span class="line">      <span class="attr">label:</span> <span class="string">master</span> <span class="string">//</span> <span class="string">分支</span></span><br><span class="line">      <span class="attr">name:</span> <span class="string">config</span> <span class="string">//</span> <span class="string">名称</span></span><br><span class="line">      <span class="attr">profile:</span> <span class="string">dev</span> <span class="string">//</span> <span class="string">环境</span></span><br><span class="line">      <span class="attr">uri:</span> <span class="string">http://localhost:?</span> <span class="string">//</span> <span class="string">config服务器地址</span></span><br><span class="line"></span><br><span class="line"><span class="string">//</span> <span class="string">注意，因为要在</span> <span class="string">application.yml</span> <span class="string">加载完成之前完成</span> <span class="string">config</span> <span class="string">的拉取，所以这些配置都要写在</span> <span class="string">bootstrap.yml</span> <span class="string">里</span></span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li><p>书写主启动类，服务端要添加 @EnableConfigServer 注解</p>
</li>
<li><p>启动</p>
</li>
<li><p>查看</p>
<ul>
<li>localhost:{port}/{lable}/{application}-{profile}.yml</li>
<li>localhost:{port}/{application}-{profile}.yml</li>
<li>localhost:{port}/{application}/{profile}[/{lable}]</li>
</ul>
</li>
</ul>
<h1 id="七、服务总线"><a href="#七、服务总线" class="headerlink" title="七、服务总线"></a>七、服务总线</h1><h2 id="7-1-Bus"><a href="#7-1-Bus" class="headerlink" title="7.1 Bus"></a>7.1 Bus</h2><h3 id="7-1-1-What-is-Bus"><a href="#7-1-1-What-is-Bus" class="headerlink" title="7.1.1 What is Bus"></a>7.1.1 What is Bus</h3><p><strong>官方文档</strong></p>
<blockquote>
<p>Spring Cloud Bus links nodes of a distributed system with a lightweight message broker. This can then be used to broadcast state changes (e.g. configuration changes) or other management instructions. AMQP and Kafka broker implementations are included with the project. Alternatively, any <a href="https://spring.io/projects/spring-cloud-stream" target="_blank" rel="noopener">Spring Cloud Stream</a> binder found on the classpath will work out of the box as a transport.</p>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>可以实现消息的全局传输，通常配合着 config，当云端的配置更改之后，能够一次性更新所有微服务</p>
</blockquote>
<h3 id="7-1-2-Dependency"><a href="#7-1-2-Dependency" class="headerlink" title="7.1.2 Dependency"></a>7.1.2 Dependency</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-bus-amqp<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="7-1-3-Use"><a href="#7-1-3-Use" class="headerlink" title="7.1.3 Use"></a>7.1.3 Use</h3><ul>
<li><p>引入依赖</p>
</li>
<li><p>修改 application.yml 或 bootstrap.yml</p>
<ul>
<li>服务端</li>
</ul>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">rabbitmq:</span></span><br><span class="line">    <span class="attr">host:</span> <span class="string">localhost</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">5672</span></span><br><span class="line">    <span class="attr">username:</span> <span class="string">guest</span></span><br><span class="line">    <span class="attr">password:</span> <span class="string">guest</span></span><br><span class="line"><span class="attr">management:</span></span><br><span class="line">  <span class="attr">endpoints:</span></span><br><span class="line">    <span class="attr">web:</span></span><br><span class="line">      <span class="attr">exposure:</span></span><br><span class="line">        <span class="attr">include:</span> <span class="string">"bus-refresh"</span></span><br></pre></td></tr></tbody></table></figure></div>

<h2 id="7-2-Stream"><a href="#7-2-Stream" class="headerlink" title="7.2 Stream"></a>7.2 Stream</h2><h3 id="7-2-1-What-is-Stream"><a href="#7-2-1-What-is-Stream" class="headerlink" title="7.2.1 What is Stream"></a>7.2.1 What is Stream</h3><p><strong>官方文档</strong></p>
<blockquote>
<p>Spring Cloud Stream is a framework for building highly scalable event-driven microservices connected with shared messaging systems.</p>
<p>The framework provides a flexible programming model built on already established and familiar Spring idioms and best practices, including support for persistent pub/sub semantics, consumer groups, and stateful partitions.</p>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>就像用 JDBC 可以操作 MySQL、Oracle 一样，Stream 是为了统一消息总线的接口而存在的，支持 rabbitMQ 和 Kafka 两大总线的通配</p>
</blockquote>
<h3 id="7-2-2-Dependency"><a href="#7-2-2-Dependency" class="headerlink" title="7.2.2 Dependency"></a>7.2.2 Dependency</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>org.springframework.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-stream-rabbit<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="7-2-3-Use"><a href="#7-2-3-Use" class="headerlink" title="7.2.3 Use"></a>7.2.3 Use</h3><ul>
<li><p>引入依赖</p>
</li>
<li><p>编写 application.yml</p>
<ul>
<li>服务端</li>
</ul>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">stream:</span></span><br><span class="line">      <span class="attr">binders:</span> <span class="string">//</span> <span class="string">定义</span> <span class="string">binder</span></span><br><span class="line">        <span class="attr">myRabbit:</span> <span class="string">//</span> <span class="string">名称自定义</span></span><br><span class="line">          <span class="attr">type:</span> <span class="string">rabbit</span> <span class="string">//</span> <span class="string">类型</span></span><br><span class="line">          <span class="attr">environment:</span> <span class="string">//环境</span></span><br><span class="line">            <span class="attr">spring:</span></span><br><span class="line">              <span class="attr">rabbitmq:</span></span><br><span class="line">                <span class="attr">host:</span> <span class="string">localhost</span> </span><br><span class="line">                <span class="attr">port:</span> <span class="number">5672</span> <span class="string">//</span> <span class="string">rabbitmq</span> <span class="string">默认注册端口</span></span><br><span class="line">                <span class="attr">username:</span> <span class="string">guest</span> <span class="string">//</span> <span class="string">rabbitmq</span> <span class="string">默认用户名</span></span><br><span class="line">                <span class="attr">password:</span> <span class="string">guest</span> <span class="string">//</span> <span class="string">rabbitmq</span> <span class="string">默认密码</span></span><br><span class="line">      <span class="attr">bindings:</span> <span class="string">//</span> <span class="string">绑定</span></span><br><span class="line">        <span class="attr">output:</span> <span class="string">//</span> <span class="string">输出</span></span><br><span class="line">          <span class="attr">destination:</span> <span class="string">CyingExchange</span> <span class="string">//</span> <span class="string">自定义一个名字</span></span><br><span class="line">          <span class="attr">port:</span> <span class="number">8500</span> <span class="string">//</span> <span class="string">服务注册中心端口</span></span><br><span class="line">          <span class="attr">discovery:</span></span><br><span class="line">            <span class="attr">service-name:</span> <span class="string">${spring.application.name}</span></span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li><p>客户端</p>
</li>
<li><pre><code class="yaml"><span class="attr">spring:</span>
  <span class="attr">cloud:</span>
    <span class="attr">stream:</span>
      <span class="attr">binders:</span> <span class="string">//</span> <span class="string">定义</span> <span class="string">binder</span>
        <span class="attr">myRabbit:</span> <span class="string">//</span> <span class="string">名称自定义</span>
          <span class="attr">type:</span> <span class="string">rabbit</span> <span class="string">//</span> <span class="string">类型</span>
          <span class="attr">environment:</span> <span class="string">//环境</span>
            <span class="attr">spring:</span>
              <span class="attr">rabbitmq:</span>
                <span class="attr">host:</span> <span class="string">localhost</span>
                <span class="attr">port:</span> <span class="number">5672</span> <span class="string">//</span> <span class="string">rabbitmq</span> <span class="string">默认注册端口</span>
                <span class="attr">username:</span> <span class="string">guest</span> <span class="string">//</span> <span class="string">rabbitmq</span> <span class="string">默认用户名</span>
                <span class="attr">password:</span> <span class="string">guest</span> <span class="string">//</span> <span class="string">rabbitmq</span> <span class="string">默认密码</span>
      <span class="attr">bindings:</span> <span class="string">//</span> <span class="string">绑定</span>
        <span class="attr">input:</span> <span class="string">//</span> <span class="string">输入</span>
          <span class="attr">destination:</span> <span class="string">CyingExchange</span> <span class="string">//</span> <span class="string">自定义一个名字</span>
          <span class="attr">content-type:</span> <span class="string">application/json</span> <span class="string">//</span> <span class="string">接收的格式</span>
          <span class="attr">binder:</span> <span class="string">myRabbit</span> <span class="string">//</span> <span class="string">使用的</span> <span class="string">binder</span>
          <span class="attr">group:</span> <span class="string">cyingOrg</span> <span class="string">//</span> <span class="string">分组，避免重复消费</span>
<span class="string"><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">Code</div></div><figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">- 编写主启动</span><br><span class="line"></span><br><span class="line">- 编写服务端与客户端</span><br><span class="line"></span><br><span class="line">  - 服务端</span><br><span class="line"></span><br><span class="line">```java</span><br><span class="line">@Service</span><br><span class="line">@EnableBinding(Source.class) // 重点</span><br><span class="line">public class PaymentServiceImpl implements PaymentService {</span><br><span class="line"></span><br><span class="line">    @Resource</span><br><span class="line">    private MessageChannel output; // 重点</span><br><span class="line"></span><br><span class="line">    public Payment getPaymentById(Long id) {</span><br><span class="line">        output.send(MessageBuilder.withPayload(“消息”).build()); //重点</span><br><span class="line">        return null;</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div></span></code></pre>
</li>
<li><p>客户端</p>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@EnableBinding</span>(Sink<span class="class">.<span class="keyword">class</span>) // 重点</span></span><br><span class="line"><span class="class">@<span class="title">Slf4j</span></span></span><br><span class="line"><span class="class">@<span class="title">Component</span> // 重点</span></span><br><span class="line"><span class="class"><span class="title">public</span> <span class="title">class</span> <span class="title">ReceiveController</span> </span>{</span><br><span class="line"></span><br><span class="line">    <span class="meta">@StreamListener</span>(Sink.INPUT) <span class="comment">//重点</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">input</span><span class="params">(Message<string> msg)</string></span> </span>{ <span class="comment">//重点</span></span><br><span class="line">        log.info(msg.getPayload()); <span class="comment">//重点</span></span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<h1 id="八、SpringCloud-Alibaba"><a href="#八、SpringCloud-Alibaba" class="headerlink" title="八、SpringCloud Alibaba"></a>八、SpringCloud Alibaba</h1><h2 id="8-1-Nacos"><a href="#8-1-Nacos" class="headerlink" title="8.1 Nacos"></a>8.1 Nacos</h2><h3 id="8-1-1-What-is-Nacos"><a href="#8-1-1-What-is-Nacos" class="headerlink" title="8.1.1 What is Nacos"></a>8.1.1 What is Nacos</h3><p><strong>官方文档</strong></p>
<blockquote>
<p>Nacos is committed to help you discover, configure, and manage your microservices. It provides a set of simple and useful features enabling you to realize dynamic service discovery, service configuration, service metadata and traffic management.</p>
<p>Nacos makes it easier and faster to construct, deliver and manage your microservices platform. It is the infrastructure that supports a service-centered modern application architecture with a microservices or cloud-native approach.</p>
</blockquote>
<p><strong>中文版</strong></p>
<blockquote>
<p>Nacos 致力于帮助您发现、配置和管理微服务。Nacos 提供了一组简单易用的特性集，帮助您快速实现动态服务发现、服务配置、服务元数据及流量管理。</p>
<p>Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。 Nacos 是构建以“服务”为中心的现代应用架构 (例如微服务范式、云原生范式) 的服务基础设施。</p>
</blockquote>
<p><strong>关键特性</strong></p>
<blockquote>
<ul>
<li><p><strong>服务发现和服务健康监测</strong></p>
<p>Nacos 支持基于 DNS 和基于 RPC 的服务发现。服务提供者使用 <a href="https://nacos.io/zh-cn/docs/sdk.html" target="_blank" rel="noopener">原生SDK</a>、<a href="https://nacos.io/zh-cn/docs/open-API.html" target="_blank" rel="noopener">OpenAPI</a>、或一个<a href="https://nacos.io/zh-cn/docs/other-language.html" target="_blank" rel="noopener">独立的Agent TODO</a>注册 Service 后，服务消费者可以使用<a href="https://nacos.io/zh-cn/docs/xx" target="_blank" rel="noopener">DNS TODO</a> 或<a href="https://nacos.io/zh-cn/docs/open-API.html" target="_blank" rel="noopener">HTTP&API</a>查找和发现服务。</p>
<p>Nacos 提供对服务的实时的健康检查，阻止向不健康的主机或服务实例发送请求。Nacos 支持传输层 (PING 或 TCP)和应用层 (如 HTTP、MySQL、用户自定义）的健康检查。 对于复杂的云环境和网络拓扑环境中（如 VPC、边缘网络等）服务的健康检查，Nacos 提供了 agent 上报模式和服务端主动检测2种健康检查模式。Nacos 还提供了统一的健康检查仪表盘，帮助您根据健康状态管理服务的可用性及流量。</p>
</li>
<li><p><strong>动态配置服务</strong></p>
<p>动态配置服务可以让您以中心化、外部化和动态化的方式管理所有环境的应用配置和服务配置。</p>
<p>动态配置消除了配置变更时重新部署应用和服务的需要，让配置管理变得更加高效和敏捷。</p>
<p>配置中心化管理让实现无状态服务变得更简单，让服务按需弹性扩展变得更容易。</p>
<p>Nacos 提供了一个简洁易用的UI (<a href="http://console.nacos.io/nacos/index.html" target="_blank" rel="noopener">控制台样例 Demo</a>) 帮助您管理所有的服务和应用的配置。Nacos 还提供包括配置版本跟踪、金丝雀发布、一键回滚配置以及客户端配置更新状态跟踪在内的一系列开箱即用的配置管理特性，帮助您更安全地在生产环境中管理配置变更和降低配置变更带来的风险。</p>
</li>
<li><p><strong>动态 DNS 服务</strong></p>
<p>动态 DNS 服务支持权重路由，让您更容易地实现中间层负载均衡、更灵活的路由策略、流量控制以及数据中心内网的简单DNS解析服务。动态DNS服务还能让您更容易地实现以 DNS 协议为基础的服务发现，以帮助您消除耦合到厂商私有服务发现 API 上的风险。</p>
<p>Nacos 提供了一些简单的 <a href="https://nacos.io/zh-cn/docs/xx" target="_blank" rel="noopener">DNS APIs TODO</a> 帮助您管理服务的关联域名和可用的 IP:PORT 列表.</p>
</li>
<li><p><strong>服务及其元数据管理</strong></p>
<p>Nacos 能让您从微服务平台建设的视角管理数据中心的所有服务及元数据，包括管理服务的描述、生命周期、服务的静态依赖分析、服务的健康状态、服务的流量管理、路由及安全策略、服务的 SLA 以及最首要的 metrics 统计数据。</p>
</li>
<li><p><a href="https://nacos.io/zh-cn/docs/roadmap.html" target="_blank" rel="noopener">更多的特性列表 …</a></p>
</li>
</ul>
</blockquote>
<p><strong>人话</strong></p>
<blockquote>
<p>Nacos 啊，是个很强大的框架，能够非常轻松的实现服务注册与发现、全局配置，而且配置都是在 web 端配置，配置好后立即生效</p>
</blockquote>
<p><strong>命名空间、分组和 DataId 的关系</strong></p>
<p>类似于 Java 的 Module、Package、Class，从逻辑上区分配置信息</p>
<p><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200505123823244.png" data-fancybox="group" data-caption="image-20200505123823244" class="fancybox"><img alt="image-20200505123823244" title="image-20200505123823244" data-src="http://narpro.top/img/image-20200505123823244.png" class="lazyload"></a></p>
<p>可以通过配置 spring.cloud.nacos.config.namespace 指定命名空间，spring.cloud.nacos.config.group 指定分组</p>
<h3 id="8-1-2-Dependency"><a href="#8-1-2-Dependency" class="headerlink" title="8.1.2 Dependency"></a>8.1.2 Dependency</h3><p><strong>服务发现</strong></p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>com.alibaba.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-alibaba-nacos-discovery<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<p><strong>服务配置</strong></p>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">xml</div></div><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">groupId</span>></span>com.alibaba.cloud<span class="tag">< /<span class="attr">groupId</span>></span></span><br><span class="line">    <span class="tag"><<span class="name">artifactId</span>></span>spring-cloud-starter-alibaba-nacos-config<span class="tag">< /<span class="attr">artifactId</span>></span></span><br><span class="line"><span class="tag">< /<span class="attr">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="8-1-3-Use"><a href="#8-1-3-Use" class="headerlink" title="8.1.3 Use"></a>8.1.3 Use</h3><ul>
<li>下载并启动 nacos</li>
</ul>
<h4 id="8-1-3-1-服务注册"><a href="#8-1-3-1-服务注册" class="headerlink" title="8.1.3.1 服务注册"></a>8.1.3.1 服务注册</h4><ul>
<li><p>引入依赖</p>
</li>
<li><p>书写 applcation.yml</p>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">nacos:</span></span><br><span class="line">      <span class="attr">discovery:</span></span><br><span class="line">        <span class="attr">server-addr:</span> <span class="string">localhost:8848</span> <span class="string">//</span> <span class="string">nacos</span> <span class="string">默认端口</span></span><br></pre></td></tr></tbody></table></figure></div>

<h4 id="8-1-3-2-服务配置"><a href="#8-1-3-2-服务配置" class="headerlink" title="8.1.3.2 服务配置"></a>8.1.3.2 服务配置</h4><ul>
<li><p>引入依赖</p>
</li>
<li><p>书写 bootstrap.yml</p>
</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">yaml</div></div><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">8081</span></span><br><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">nacos:</span></span><br><span class="line">      <span class="attr">discovery:</span></span><br><span class="line">        <span class="attr">server-addr:</span> <span class="string">localhost:8848</span></span><br><span class="line">      <span class="attr">config:</span></span><br><span class="line">        <span class="attr">server-addr:</span> <span class="string">localhost:8848</span></span><br><span class="line">        <span class="attr">file-extension:</span> <span class="string">yaml</span></span><br></pre></td></tr></tbody></table></figure></div>

<ul>
<li><p>书写 application.yml</p>
<ul>
<li><pre><code class="yaml"><span class="attr">spring:</span>
  <span class="attr">profiles:</span>
    <span class="attr">active:</span> <span class="string">dev</span>
<span class="string"><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">Code</div></div><figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">- 书写主启动</span><br><span class="line"></span><br><span class="line">- 书写 controller 并添加 @RefreshScope 注解</span><br><span class="line"></span><br><span class="line">- 在 Nacos 的 web 端添加配置</span><br><span class="line"></span><br><span class="line">- ![image-20200505123212448](http://narpro.top/img/image-20200505123212448.png)</span><br><span class="line"></span><br><span class="line">- ![image-20200505123410351](http://narpro.top/img/image-20200505123410351.png)</span><br><span class="line"></span><br><span class="line">- ![image-20200505123433046](http://narpro.top/img/image-20200505123433046.png)</span><br><span class="line"></span><br><span class="line">- 启动微服务，并尝试访问 /get/config 展示配置内容，试图修改一下配置内容，发布后，刷新一下 /get/config 页面，发现配置立即同步</span><br><span class="line"></span><br><span class="line">## 8.2 Sentinel</span><br><span class="line"></span><br><span class="line">### 8.2.1 What is Sentinel</span><br><span class="line"></span><br><span class="line">**官方文档 ** [链接](https://github.com/alibaba/Sentinel/wiki)</span><br><span class="line"></span><br><span class="line">> As distributed systems are becoming increasingly popular, the reliability between services is becoming more important than ever before. Sentinel is a powerful flow control component that takes "flow" as the breakthrough point and covers multiple fields including flow control, concurrency limiting, circuit breaking, and adaptive system protection to guarantee the reliability of microservices.</span><br><span class="line"></span><br><span class="line">**人话**</span><br><span class="line"></span><br><span class="line">> 用于替代 Hystrix 做服务限流、熔断、降级</span><br><span class="line"></span><br><span class="line">### 8.2.2 Dependency</span><br><span class="line"></span><br><span class="line">```xml</span><br><span class="line"><dependency></dependency></span><br><span class="line">    <groupid>com.alibaba.cloud< /groupId></groupid></span><br><span class="line">    <artifactid>spring-cloud-starter-alibaba-sentinel< /artifactId></artifactid></span><br><span class="line">< /dependency></span><br></pre></td></tr></tbody></table></figure></div></span>
</code></pre>
</li>
</ul>
</li>
</ul>
<h3 id="8-2-3-Use"><a href="#8-2-3-Use" class="headerlink" title="8.2.3 Use"></a>8.2.3 Use</h3><ul>
<li>引入依赖</li>
<li>下载并启动 sentinel</li>
<li>书写主启动类</li>
<li>书写 Controller</li>
<li>启动微服务</li>
</ul>
<h4 id="8-2-3-1-流量控制"><a href="#8-2-3-1-流量控制" class="headerlink" title="8.2.3.1 流量控制"></a>8.2.3.1 流量控制</h4><p><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200426222039556.png" data-fancybox="group" data-caption="image-20200426222039556" class="fancybox"><img alt="image-20200426222039556" title="image-20200426222039556" data-src="http://narpro.top/img/image-20200426222039556.png" class="lazyload"></a></p>
<ul>
<li>资源名：url 地址</li>
<li>针对来源：</li>
<li>阈值类型：<ul>
<li>QPS：每秒钟允许请求的次数</li>
<li>线程数：服务器内部能同时处理的线程数</li>
</ul>
</li>
<li>单机阈值：对阈值类型设置数量</li>
<li>是否集群</li>
<li>流控模式：<ul>
<li>直接：对资源本身</li>
<li>关联：资源本身繁忙，从而限制指定关联的资源</li>
</ul>
</li>
<li>流控效果：<ul>
<li>快速失败：一旦请求超过阈值（每秒请求次数超出，或者同时需要的线程数多余设置的线程数）则直接报错</li>
<li>Warm up：让服务器能承载的阈值上限逐渐上升</li>
<li>排队等待：不管来多少请求，不会拒绝，只不过一个一个处理</li>
</ul>
</li>
</ul>
<h5 id="8-2-3-1-1-QPS-直接-快速失败"><a href="#8-2-3-1-1-QPS-直接-快速失败" class="headerlink" title="8.2.3.1.1 QPS-直接-快速失败"></a>8.2.3.1.1 QPS-直接-快速失败</h5><p>一旦一秒内请求次数超过 QPS 能够承载的阈值，则直接服务限流【<code>Blocked By Sentinel(flow limiting)</code>】</p>
<h5 id="8-2-3-1-2-线程数-直接-快速失败"><a href="#8-2-3-1-2-线程数-直接-快速失败" class="headerlink" title="8.2.3.1.2 线程数-直接-快速失败"></a>8.2.3.1.2 线程数-直接-快速失败</h5><p>一旦同时请求的线程数超过了设置的线程数，则直接服务限流</p>
<h5 id="8-2-3-1-3-QPS-关联-快速失败"><a href="#8-2-3-1-3-QPS-关联-快速失败" class="headerlink" title="8.2.3.1.3 QPS-关联-快速失败"></a>8.2.3.1.3 QPS-关联-快速失败</h5><p>如果 A 的流控关联了 B，而 A 的请求超出了所承受的最高阈值，则 B 被限流。比如 A 是支付，B 是下单，A 的支付都忙不过来，那 B 的下单利索当然要被迫限流等一等</p>
<h5 id="8-2-3-1-4-QPS-直接-warm-up"><a href="#8-2-3-1-4-QPS-直接-warm-up" class="headerlink" title="8.2.3.1.4  QPS-直接-warm up"></a>8.2.3.1.4  QPS-直接-warm up</h5><p>选择后会出现新的文本框</p>
<p><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200426224259471.png" data-fancybox="group" data-caption="image-20200426224259471" class="fancybox"><img alt="image-20200426224259471" title="image-20200426224259471" data-src="http://narpro.top/img/image-20200426224259471.png" class="lazyload"></a></p>
<p>冷因子默认是 3，设阈值为 10，预热时长为 5，则一开始能承载的最大阈值为 10/3=3 个请求，5 秒之后，渐渐的能承载 10 个</p>
<h5 id="8-2-3-1-5-QPS-直接-排队等待"><a href="#8-2-3-1-5-QPS-直接-排队等待" class="headerlink" title="8.2.3.1.5 QPS-直接-排队等待"></a>8.2.3.1.5 QPS-直接-排队等待</h5><p>根据 QPS 的阈值，确定每秒处理多少个请求</p>
<h4 id="8-2-3-2-熔断降级"><a href="#8-2-3-2-熔断降级" class="headerlink" title="8.2.3.2 熔断降级"></a>8.2.3.2 熔断降级</h4><p><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200426225356181.png" data-fancybox="group" data-caption="image-20200426225356181" class="fancybox"><img alt="image-20200426225356181" title="image-20200426225356181" data-src="http://narpro.top/img/image-20200426225356181.png" class="lazyload"></a></p>
<ul>
<li>资源名：url 地址</li>
<li>降级策略：以下均是窗口期内通过的请求 >= 5 才生效<ul>
<li>RT：平均响应时间（秒级），超出阈值生效。RT 最大 4900。可通过 <code>-Dcsp.sentinel.statistic.max.rt=?</code> 配置更高的</li>
<li>异常比例：异常出现的比例（秒级），超过阈值生效</li>
<li>异常数：异常出现的次数（秒级），查过阈值生效</li>
</ul>
</li>
</ul>
<h5 id="8-2-3-2-1-RT"><a href="#8-2-3-2-1-RT" class="headerlink" title="8.2.3.2.1 RT"></a>8.2.3.2.1 RT</h5><p>设 RT 为 200ms，时间窗口为 1，程序需要执行时间 1s，则发送 5 次及以上请求，这些请求还是会继续执行，但因为时间超过了 200ms，那么在下一秒将会处于降级期</p>
<h5 id="8-2-3-2-2-异常比例"><a href="#8-2-3-2-2-异常比例" class="headerlink" title="8.2.3.2.2 异常比例"></a>8.2.3.2.2 异常比例</h5><p>设异常比例为 0.2，时间窗口为 1 ，则发送 5 次及以上请求，在一秒内一旦有 20% 的请求出错，那么在下一秒将会处于降级期，而且此处只进行服务降级，即请求异常超过一定比例就降级，并不会处理异常，所以如果在没达到条件的情况下，程序抛出异常，异常将会按照规定返回给前端</p>
<h5 id="8-2-3-2-3-异常数"><a href="#8-2-3-2-3-异常数" class="headerlink" title="8.2.3.2.3 异常数"></a>8.2.3.2.3 异常数</h5><p>设异常数为 10，时间窗口为 1 ，则发送 5 次及以上请求，在一分钟内，一旦有 10 个请求抛出异常，那么在下一秒内会处于降级期</p>
<h4 id="8-2-3-3-热点"><a href="#8-2-3-3-热点" class="headerlink" title="8.2.3.3 热点"></a>8.2.3.3 热点</h4><p><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200426233125554.png" data-fancybox="group" data-caption="image-20200426233125554" class="fancybox"><img alt="image-20200426233125554" title="image-20200426233125554" data-src="http://narpro.top/img/image-20200426233125554.png" class="lazyload"></a></p>
<ul>
<li>资源名：注解中的指定名</li>
<li>限流模式</li>
<li>参数索引：注解所在方法的第几个参数</li>
<li>单位阈值：允许的请求数</li>
<li>统计窗口时长</li>
</ul>
<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping</span>(value = <span class="string">"/hotkey"</span>)</span><br><span class="line"><span class="meta">@SentinelResource</span>(</span><br><span class="line">    value = <span class="string">"hotkey"</span>,</span><br><span class="line">    blockHandler = <span class="string">"hotkeyHandler"</span></span><br><span class="line">)</span><br><span class="line"><span class="function"><span class="keyword">public</span> CommonResult<string> <span class="title">hotKey</span><span class="params">(</span></string></span></span><br><span class="line"><span class="function"><span class="params">    @RequestParam(value = <span class="string">"p1"</span>, required = <span class="keyword">false</span>)</span> String p1,</span></span><br><span class="line"><span class="function">    @<span class="title">RequestParam</span><span class="params">(value = <span class="string">"p2"</span>, required = <span class="keyword">false</span>)</span> String p2</span></span><br><span class="line"><span class="function">) </span>{</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<string>(<span class="number">200</span>, <span class="string">"p1: "</span> + p1 + <span class="string">", p2: "</span> + p2);</string></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> CommonResult<string> <span class="title">hotkeyHandler</span><span class="params">(</span></string></span></span><br><span class="line"><span class="function"><span class="params">    String p1, </span></span></span><br><span class="line"><span class="function"><span class="params">    String p2, </span></span></span><br><span class="line"><span class="function"><span class="params">    BlockException e</span></span></span><br><span class="line"><span class="function"><span class="params">)</span> </span>{</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<string>(</string></span><br><span class="line">        <span class="number">200</span>, </span><br><span class="line">        <span class="string">"p1: "</span> + p1 + <span class="string">", p2: "</span> + p2, </span><br><span class="line">        e.getMessage()</span><br><span class="line">    );</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<p>若要检测 p1，即第 0 个参数</p>
<p>设资源名为 hotkey，参数索引为 0，单位阈值为 1，统计窗口时长为 1，则当访问 /hotkey 时，带有 p1 的情况下，1 秒钟只能发送 1 次请求，否则就会进入 hotkeyHandler 方法进行降级处理</p>
<p>当热点配置成功后还能继续追加高级操作</p>
<p><a target="_blank" rel="noopener" href="http://narpro.top/img/image-20200426235645914.png" data-fancybox="group" data-caption="image-20200426235645914" class="fancybox"><img alt="image-20200426235645914" title="image-20200426235645914" data-src="http://narpro.top/img/image-20200426235645914.png" class="lazyload"></a></p>
<ul>
<li>参数类型：只支持 8 个基本类型和 String</li>
<li>参数值：可以额外考虑的值</li>
<li>限流阈值</li>
</ul>
<p>设参数类型为 String，参数值为 250，限流阈值为 10，其他与上面相同，则 p1 值是 250 时，每秒要达到 10 次后才降级</p>
<h4 id="8-2-3-4-SentinelResource"><a href="#8-2-3-4-SentinelResource" class="headerlink" title="8.2.3.4 @SentinelResource"></a>8.2.3.4 @SentinelResource</h4><h5 id="8-2-3-4-1-局部"><a href="#8-2-3-4-1-局部" class="headerlink" title="8.2.3.4.1 局部"></a>8.2.3.4.1 局部</h5><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SentinelResource</span>(</span><br><span class="line">    value = <span class="string">"fallback"</span>,</span><br><span class="line">    fallback = <span class="string">"getFallbackHandler"</span>, <span class="comment">// 当程序抛出异常时执行</span></span><br><span class="line">    blockHandler = <span class="string">"getBlockHandler"</span> <span class="comment">// 当被限流熔断降级时执行</span></span><br><span class="line">)</span><br><span class="line"><span class="meta">@GetMapping</span>(value = <span class="string">"/s/get/{id}"</span>)</span><br><span class="line"><span class="function"><span class="keyword">public</span> CommonResult<payment> <span class="title">get</span><span class="params">(@PathVariable(<span class="string">"id"</span>)</span> Long id) </payment></span>{</span><br><span class="line">    <span class="keyword">if</span> (id == <span class="number">3L</span>) {</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> IllegalArgumentException(<span class="string">"非法参数"</span>);</span><br><span class="line">    }</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<>(<span class="number">200</span>, Thread.currentThread().getName(), <span class="string">"Success"</span>, service.getPaymentById(id));</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> CommonResult<payment> <span class="title">getFallbackHandler</span><span class="params">(@PathVariable(<span class="string">"id"</span>)</span> Long id, Throwable e) </payment></span>{</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<>(<span class="number">404</span>, Thread.currentThread().getName(), e.getMessage(), <span class="keyword">new</span> Payment());</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> CommonResult<payment> <span class="title">getBlockHandler</span><span class="params">(@PathVariable(<span class="string">"id"</span>)</span> Long id, BlockException e) </payment></span>{</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<payment>(<span class="number">404</span>, Thread.currentThread().getName(), <span class="string">"Blocked By Cying"</span>, <span class="keyword">new</span> Payment());</payment></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<h5 id="8-2-3-4-2-全局"><a href="#8-2-3-4-2-全局" class="headerlink" title="8.2.3.4.2 全局"></a>8.2.3.4.2 全局</h5><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyGlobalHandler</span> </span>{</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> CommonResult<payment> <span class="title">getHandler</span><span class="params">(Long id, BlockException e)</span> </payment></span>{</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<>(<span class="number">404</span>, Thread.currentThread().getName(), <span class="string">"请求过快"</span>, <span class="keyword">new</span> Payment());</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">java</div></div><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">PaymentController</span> </span>{</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Resource</span></span><br><span class="line">    <span class="keyword">private</span> PaymentServiceImpl service;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@SentinelResource</span>(</span><br><span class="line">            value = <span class="string">"getPaymentById"</span>,</span><br><span class="line">            blockHandlerClass = MyGlobalHandler<span class="class">.<span class="keyword">class</span>, // 指定类</span></span><br><span class="line"><span class="class">            <span class="title">blockHandler</span> </span>= <span class="string">"getHandler"</span> <span class="comment">// 指定方法</span></span><br><span class="line">    )</span><br><span class="line">    <span class="meta">@GetMapping</span>(value = <span class="string">"/s/get/{id}"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> CommonResult<payment> <span class="title">get</span><span class="params">(@PathVariable(<span class="string">"id"</span>)</span> Long id) </payment></span>{</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> CommonResult<>(<span class="number">200</span>, Thread.currentThread().getName(), <span class="string">"Success"</span>, service.getPayment(id));</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure></div>

<h1 id="九、附录"><a href="#九、附录" class="headerlink" title="九、附录"></a>九、附录</h1><h2 id="9-1-Eureka-Properties"><a href="#9-1-Eureka-Properties" class="headerlink" title="9.1 Eureka Properties"></a>9.1 Eureka Properties</h2><h3 id="9-1-1-instance"><a href="#9-1-1-instance" class="headerlink" title="9.1.1 instance"></a>9.1.1 instance</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">Code</div></div><figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">#服务注册中心实例的主机名</span><br><span class="line">eureka.instance.hostname=localhost</span><br><span class="line">#注册在Eureka服务中的应用组名</span><br><span class="line">eureka.instance.app-group-name=</span><br><span class="line">#注册在的Eureka服务中的应用名称</span><br><span class="line">eureka.instance.appname=</span><br><span class="line">#该实例注册到服务中心的唯一ID</span><br><span class="line">eureka.instance.instance-id=</span><br><span class="line">#该实例的IP地址</span><br><span class="line">eureka.instance.ip-address=</span><br><span class="line">#该实例，相较于hostname是否优先使用IP</span><br><span class="line">eureka.instance.prefer-ip-address=false</span><br><span class="line">#用于AWS平台自动扩展的与此实例关联的组名，</span><br><span class="line">eureka.instance.a-s-g-name=</span><br><span class="line">#部署此实例的数据中心</span><br><span class="line">eureka.instance.data-center-info=</span><br><span class="line">#默认的地址解析顺序</span><br><span class="line">eureka.instance.default-address-resolution-order=</span><br><span class="line">#该实例的环境配置</span><br><span class="line">eureka.instance.environment=</span><br><span class="line">#初始化该实例，注册到服务中心的初始状态</span><br><span class="line">eureka.instance.initial-status=up</span><br><span class="line">#表明是否只要此实例注册到服务中心，立马就进行通信</span><br><span class="line">eureka.instance.instance-enabled-onit=false</span><br><span class="line">#该服务实例的命名空间,用于查找属性</span><br><span class="line">eureka.instance.namespace=eureka</span><br><span class="line">#该服务实例的子定义元数据，可以被服务中心接受到</span><br><span class="line">eureka.instance.metadata-map.test = test</span><br><span class="line">#服务中心删除此服务实例的等待时间(秒为单位),时间间隔为最后一次服务中心接受到的心跳时间</span><br><span class="line">eureka.instance.lease-expiration-duration-in-seconds=90</span><br><span class="line">#该实例给服务中心发送心跳的间隔时间，用于表明该服务实例可用</span><br><span class="line">eureka.instance.lease-renewal-interval-in-seconds=30</span><br><span class="line">#该实例，注册服务中心，默认打开的通信数量</span><br><span class="line">eureka.instance.registry.default-open-for-traffic-count=1</span><br><span class="line">#每分钟续约次数</span><br><span class="line">eureka.instance.registry.expected-number-of-renews-per-min=1</span><br><span class="line">#该实例健康检查url,绝对路径</span><br><span class="line">eureka.instance.health-check-url=</span><br><span class="line">#该实例健康检查url,相对路径</span><br><span class="line">eureka.instance.health-check-url-path=/health</span><br><span class="line">#该实例的主页url,绝对路径</span><br><span class="line">eureka.instance.home-page-url=</span><br><span class="line">#该实例的主页url,相对路径</span><br><span class="line">eureka.instance.home-page-url-path=/</span><br><span class="line">#该实例的安全健康检查url,绝对路径</span><br><span class="line">eureka.instance.secure-health-check-url=</span><br><span class="line">#https通信端口</span><br><span class="line">eureka.instance.secure-port=443</span><br><span class="line">#https通信端口是否启用</span><br><span class="line">eureka.instance.secure-port-enabled=false</span><br><span class="line">#http通信端口</span><br><span class="line">eureka.instance.non-secure-port=80</span><br><span class="line">#http通信端口是否启用</span><br><span class="line">eureka.instance.non-secure-port-enabled=true</span><br><span class="line">#该实例的安全虚拟主机名称(https)</span><br><span class="line">eureka.instance.secure-virtual-host-name=unknown</span><br><span class="line">#该实例的虚拟主机名称(http)</span><br><span class="line">eureka.instance.virtual-host-name=unknown</span><br><span class="line">#该实例的状态呈现url,绝对路径</span><br><span class="line">eureka.instance.status-page-url=</span><br><span class="line">#该实例的状态呈现url,相对路径</span><br><span class="line">eureka.instance.status-page-url-path=/status</span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="9-1-2-server"><a href="#9-1-2-server" class="headerlink" title="9.1.2 server"></a>9.1.2 server</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">Code</div></div><figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">#服务端开启自我保护模式。无论什么情况，服务端都会保持一定数量的服务。避免client与server的网络问题，而出现大量的服务被清除。</span><br><span class="line">eureka.server.enable-self-preservation=true</span><br><span class="line">#开启清除无效服务的定时任务，时间间隔。默认1分钟</span><br><span class="line">eureka.server.eviction-interval-timer-in-ms= 60000</span><br><span class="line">#间隔多长时间，清除过期的delta数据</span><br><span class="line">eureka.server.delta-retention-timer-interval-in-ms=0</span><br><span class="line">#过期数据，是否也提供给client</span><br><span class="line">eureka.server.disable-delta=false</span><br><span class="line">#eureka服务端是否记录client的身份header</span><br><span class="line">eureka.server.log-identity-headers=true</span><br><span class="line">#请求频率限制器</span><br><span class="line">eureka.server.rate-limiter-burst-size=10</span><br><span class="line">#是否开启请求频率限制器</span><br><span class="line">eureka.server.rate-limiter-enabled=false</span><br><span class="line">#请求频率的平均值</span><br><span class="line">eureka.server.rate-limiter-full-fetch-average-rate=100</span><br><span class="line">#是否对标准的client进行频率请求限制。如果是false，则只对非标准client进行限制</span><br><span class="line">eureka.server.rate-limiter-throttle-standard-clients=false</span><br><span class="line">#注册服务、拉去服务列表数据的请求频率的平均值</span><br><span class="line">eureka.server.rate-limiter-registry-fetch-average-rate=500</span><br><span class="line">#设置信任的client list</span><br><span class="line">eureka.server.rate-limiter-privileged-clients=</span><br><span class="line">#在设置的时间范围类，期望与client续约的百分比。</span><br><span class="line">eureka.server.renewal-percent-threshold=0.85</span><br><span class="line">#多长时间更新续约的阈值</span><br><span class="line">eureka.server.renewal-threshold-update-interval-ms=0</span><br><span class="line">#对于缓存的注册数据，多长时间过期</span><br><span class="line">eureka.server.response-cache-auto-expiration-in-seconds=180</span><br><span class="line">#多长时间更新一次缓存中的服务注册数据</span><br><span class="line">eureka.server.response-cache-update-interval-ms=0</span><br><span class="line">#缓存增量数据的时间，以便在检索的时候不丢失信息</span><br><span class="line">eureka.server.retention-time-in-m-s-in-delta-queue=0</span><br><span class="line">#当时间戳不一致的时候，是否进行同步</span><br><span class="line">eureka.server.sync-when-timestamp-differs=true</span><br><span class="line">#是否采用只读缓存策略，只读策略对于缓存的数据不会过期。</span><br><span class="line">eureka.server.use-read-only-response-cache=true</span><br></pre></td></tr></tbody></table></figure></div>

<h3 id="9-1-3-client"><a href="#9-1-3-client" class="headerlink" title="9.1.3 client"></a>9.1.3 client</h3><div class="code-area-wrap"><div class="highlight-tools"><i class="fa fa-angle-down code-expand" aria-hidden="true"></i><div class="code_lang">Code</div></div><figure class="highlight plain"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br></pre></td><td class="code"><pre><span class="line">#该客户端是否可用</span><br><span class="line">eureka.client.enabled=true</span><br><span class="line">#实例是否在eureka服务器上注册自己的信息以供其他服务发现，默认为true</span><br><span class="line">eureka.client.register-with-eureka=false</span><br><span class="line">#此客户端是否获取eureka服务器注册表上的注册信息，默认为true</span><br><span class="line">eureka.client.fetch-registry=false</span><br><span class="line">#是否过滤掉，非UP的实例。默认为true</span><br><span class="line">eureka.client.filter-only-up-instances=true</span><br><span class="line">#与Eureka注册服务中心的通信zone和url地址</span><br><span class="line">eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/</span><br><span class="line"></span><br><span class="line">#client连接Eureka服务端后的空闲等待时间，默认为30 秒</span><br><span class="line">eureka.client.eureka-connection-idle-timeout-seconds=30</span><br><span class="line">#client连接eureka服务端的连接超时时间，默认为5秒</span><br><span class="line">eureka.client.eureka-server-connect-timeout-seconds=5</span><br><span class="line">#client对服务端的读超时时长</span><br><span class="line">eureka.client.eureka-server-read-timeout-seconds=8</span><br><span class="line">#client连接all eureka服务端的总连接数，默认200</span><br><span class="line">eureka.client.eureka-server-total-connections=200</span><br><span class="line">#client连接eureka服务端的单机连接数量，默认50</span><br><span class="line">eureka.client.eureka-server-total-connections-per-host=50</span><br><span class="line">#执行程序指数回退刷新的相关属性，是重试延迟的最大倍数值，默认为10</span><br><span class="line">eureka.client.cache-refresh-executor-exponential-back-off-bound=10</span><br><span class="line">#执行程序缓存刷新线程池的大小，默认为5</span><br><span class="line">eureka.client.cache-refresh-executor-thread-pool-size=2</span><br><span class="line">#心跳执行程序回退相关的属性，是重试延迟的最大倍数值，默认为10</span><br><span class="line">eureka.client.heartbeat-executor-exponential-back-off-bound=10</span><br><span class="line">#心跳执行程序线程池的大小,默认为5</span><br><span class="line">eureka.client.heartbeat-executor-thread-pool-size=5</span><br><span class="line"># 询问Eureka服务url信息变化的频率（s），默认为300秒</span><br><span class="line">eureka.client.eureka-service-url-poll-interval-seconds=300</span><br><span class="line">#最初复制实例信息到eureka服务器所需的时间（s），默认为40秒</span><br><span class="line">eureka.client.initial-instance-info-replication-interval-seconds=40</span><br><span class="line">#间隔多长时间再次复制实例信息到eureka服务器，默认为30秒</span><br><span class="line">eureka.client.instance-info-replication-interval-seconds=30</span><br><span class="line">#从eureka服务器注册表中获取注册信息的时间间隔（s），默认为30秒</span><br><span class="line">eureka.client.registry-fetch-interval-seconds=30</span><br><span class="line"></span><br><span class="line"># 获取实例所在的地区。默认为us-east-1</span><br><span class="line">eureka.client.region=us-east-1</span><br><span class="line">#实例是否使用同一zone里的eureka服务器，默认为true，理想状态下，eureka客户端与服务端是在同一zone下</span><br><span class="line">eureka.client.prefer-same-zone-eureka=true</span><br><span class="line"># 获取实例所在的地区下可用性的区域列表，用逗号隔开。（AWS）</span><br><span class="line">eureka.client.availability-zones.china=defaultZone,defaultZone1,defaultZone2</span><br><span class="line">#eureka服务注册表信息里的以逗号隔开的地区名单，如果不这样返回这些地区名单，则客户端启动将会出错。默认为null</span><br><span class="line">eureka.client.fetch-remote-regions-registry=</span><br><span class="line">#服务器是否能够重定向客户端请求到备份服务器。 如果设置为false，服务器将直接处理请求，如果设置为true，它可能发送HTTP重定向到客户端。默认为false</span><br><span class="line">eureka.client.allow-redirects=false</span><br><span class="line">#客户端数据接收</span><br><span class="line">eureka.client.client-data-accept=</span><br><span class="line">#增量信息是否可以提供给客户端看，默认为false</span><br><span class="line">eureka.client.disable-delta=false</span><br><span class="line">#eureka服务器序列化/反序列化的信息中获取“_”符号的的替换字符串。默认为“__“</span><br><span class="line">eureka.client.escape-char-replacement=__</span><br><span class="line">#eureka服务器序列化/反序列化的信息中获取“$”符号的替换字符串。默认为“_-”</span><br><span class="line">eureka.client.dollar-replacement="_-"</span><br><span class="line">#当服务端支持压缩的情况下，是否支持从服务端获取的信息进行压缩。默认为true</span><br><span class="line">eureka.client.g-zip-content=true</span><br><span class="line">#是否记录eureka服务器和客户端之间在注册表的信息方面的差异，默认为false</span><br><span class="line">eureka.client.log-delta-diff=false</span><br><span class="line"># 如果设置为true,客户端的状态更新将会点播更新到远程服务器上，默认为true</span><br><span class="line">eureka.client.on-demand-update-status-change=true</span><br><span class="line">#此客户端只对一个单一的VIP注册表的信息感兴趣。默认为null</span><br><span class="line">eureka.client.registry-refresh-single-vip-address=</span><br><span class="line">#client是否在初始化阶段强行注册到服务中心，默认为false</span><br><span class="line">eureka.client.should-enforce-registration-at-init=false</span><br><span class="line">#client在shutdown的时候是否显示的注销服务从服务中心，默认为true</span><br><span class="line">eureka.client.should-unregister-on-shutdown=true</span><br><span class="line"></span><br><span class="line"># 获取eureka服务的代理主机，默认为null</span><br><span class="line">eureka.client.proxy-host=</span><br><span class="line">#获取eureka服务的代理密码，默认为null</span><br><span class="line">eureka.client.proxy-password=</span><br><span class="line"># 获取eureka服务的代理端口, 默认为null</span><br><span class="line">eureka.client.proxy-port=</span><br><span class="line"># 获取eureka服务的代理用户名，默认为null</span><br><span class="line">eureka.client.proxy-user-name=</span><br><span class="line"></span><br><span class="line">#属性解释器</span><br><span class="line">eureka.client.property-resolver=</span><br><span class="line">#获取实现了eureka客户端在第一次启动时读取注册表的信息作为回退选项的实现名称</span><br><span class="line">eureka.client.backup-registry-impl=</span><br><span class="line">#这是一个短暂的×××的配置，如果最新的×××是稳定的，则可以去除，默认为null</span><br><span class="line">eureka.client.decoder-name=</span><br><span class="line">#这是一个短暂的编码器的配置，如果最新的编码器是稳定的，则可以去除，默认为null</span><br><span class="line">eureka.client.encoder-name=</span><br><span class="line"></span><br><span class="line">#是否使用DNS机制去获取服务列表，然后进行通信。默认为false</span><br><span class="line">eureka.client.use-dns-for-fetching-service-urls=false</span><br><span class="line">#获取要查询的DNS名称来获得eureka服务器，此配置只有在eureka服务器ip地址列表是在DNS中才会用到。默认为null</span><br><span class="line">eureka.client.eureka-server-d-n-s-name=</span><br><span class="line">#获取eureka服务器的端口，此配置只有在eureka服务器ip地址列表是在DNS中才会用到。默认为null</span><br><span class="line">eureka.client.eureka-server-port=</span><br><span class="line">#表示eureka注册中心的路径，如果配置为eureka，则为http://x.x.x.x:x/eureka/，在eureka的配置文件中加入此配置表示eureka作为客户端向注册中心注册，从而构成eureka集群。此配置只有在eureka服务器ip地址列表是在DNS中才会用到，默认为null</span><br><span class="line">eureka.client.eureka-server-u-r-l-context=</span><br></pre></td></tr></tbody></table></figure></div>

<h2 id="9-2-Zookeeper"><a href="#9-2-Zookeeper" class="headerlink" title="9.2 Zookeeper"></a>9.2 Zookeeper</h2><table>
<thead>
<tr>
<th>属性名</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>spring.cloud.zookeeper.base-sleep-time-ms</td>
<td>50</td>
<td>重试之间等待的初始时间</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.block-until-connected-unit</td>
<td></td>
<td>与Zookeeper连接时阻止的时间单位</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.block-until-connected-wait</td>
<td>10</td>
<td>等待时间阻止连接到Zookeeper</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.connect-string</td>
<td>localhost:2181</td>
<td>连接字符串到Zookeeper集群</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.default-health-endpoint</td>
<td></td>
<td>将检查以验证依赖关系是否存在的默认运行状况端点</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.dependencies</td>
<td></td>
<td>将别名映射到ZookeeperDependency。从Ribbon的角度看，别名实际上是serviceID，因为Ribbon不能接受serviceID中的嵌套结构</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.dependency-configurations</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.zookeeper.dependency-names</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.zookeeper.discovery.enabled</td>
<td>TRUE</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.zookeeper.discovery.instance-host</td>
<td></td>
<td>预定义的主机可以在Zookeeper中注册自己的服务。对应于URI规范中的{code address}。</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.discovery.instance-port</td>
<td></td>
<td>端口注册服务（默认为侦听端口）</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.discovery.metadata</td>
<td></td>
<td>获取与此实例关联的元数据名称/值对。该信息被发送到动物管理员，可以被其他实例使用。</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.discovery.register</td>
<td>TRUE</td>
<td>在zookeeper中注册为服务。</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.discovery.root</td>
<td>/services</td>
<td>所有实例都被注册的根Zookeeper文件夹</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.discovery.uri-spec</td>
<td>{scheme}://{address}:{port}</td>
<td>在Zookeeper服务注册期间解决的URI规范</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.enabled</td>
<td>TRUE</td>
<td>启用Zookeeper</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.max-retries</td>
<td>10</td>
<td>最多重试次数</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.max-sleep-ms</td>
<td>500</td>
<td>每次重试最多可以以ms为单位睡眠</td>
</tr>
<tr>
<td>spring.cloud.zookeeper.prefix</td>
<td></td>
<td>将应用于所有Zookeeper依赖关系的路径的公共前缀</td>
</tr>
</tbody></table>
<h2 id="9-3-Consul"><a href="#9-3-Consul" class="headerlink" title="9.3 Consul"></a>9.3 Consul</h2><table>
<thead>
<tr>
<th>属性名</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>spring.cloud.consul.discovery.acl-token</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.catalog-services-watch-delay</td>
<td>10</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.catalog-services-watch-timeout</td>
<td>2</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.default-query-tag</td>
<td></td>
<td>如果没有在serverListQueryTags中列出，请在服务列表中查询标签。</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.default-zone-metadata-name</td>
<td>zone</td>
<td>服务实例区域来自元数据。这允许更改元数据标签名称。</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.enabled</td>
<td>TRUE</td>
<td>是否启用服务发现</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.fail-fast</td>
<td>TRUE</td>
<td>在服务注册期间抛出异常，如果为true，否则，记录警告（默认为true）。</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.health-check-interval</td>
<td>10</td>
<td>执行健康检查的频率（例如10s）</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.health-check-path</td>
<td>/health</td>
<td>调用健康检查的备用服务器路径</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.health-check-timeout</td>
<td>10</td>
<td>健康检查超时（例如10s）</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.health-check-url</td>
<td></td>
<td>自定义健康检查网址覆盖默认值</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.heartbeat.enabled</td>
<td>FALSE</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.heartbeat.heartbeat-interval</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.heartbeat.interval-ratio</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.heartbeat.ttl-unit</td>
<td>s</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.heartbeat.ttl-value</td>
<td>30</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.host-info</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.hostname</td>
<td></td>
<td>访问服务器时使用的主机名</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.instance-id</td>
<td></td>
<td>唯一的服务实例ID</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.instance-zone</td>
<td></td>
<td>服务实例区</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.ip-address</td>
<td></td>
<td>访问服务时使用的IP地址（还必须设置preferIpAddress才能使用）</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.lifecycle.enabled</td>
<td>TRUE</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.management-port</td>
<td></td>
<td>端口注册管理服务（默认为管理端口）</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.management-suffix</td>
<td>management</td>
<td>注册管理服务时使用后缀</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.management-tags</td>
<td></td>
<td>注册管理服务时使用的标签</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.port</td>
<td></td>
<td>端口注册服务（默认为侦听端口）</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.prefer-agent-address</td>
<td>FALSE</td>
<td>我们将如何确定使用地址的来源</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.prefer-ip-address</td>
<td>FALSE</td>
<td>在注册时使用ip地址而不是主机名</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.query-passing</td>
<td>FALSE</td>
<td>将“pass”参数添加到/ v1 / health / service / serviceName。这会将健康检查推送到服务器。</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.register</td>
<td>TRUE</td>
<td>注册为领事服务。</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.register-health-check</td>
<td>TRUE</td>
<td>注册领事健康检查。在开发服务期间有用。</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.scheme</td>
<td>http</td>
<td>是否注册http或https服务</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.server-list-query-tags</td>
<td></td>
<td>服务器列表中要查询的serviceId的→标签的映射。这允许通过单个标签过滤服务。</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.service-name</td>
<td></td>
<td>服务名称</td>
</tr>
<tr>
<td>spring.cloud.consul.discovery.tags</td>
<td></td>
<td>注册服务时使用的标签</td>
</tr>
<tr>
<td>spring.cloud.consul.enabled</td>
<td>TRUE</td>
<td>启用了spring cloud consul</td>
</tr>
<tr>
<td>spring.cloud.consul.host</td>
<td>localhost</td>
<td>Consul代理主机名。默认为“localhost”。</td>
</tr>
<tr>
<td>spring.cloud.consul.port</td>
<td>8500</td>
<td>Consul代理端口。默认为’8500’。</td>
</tr>
<tr>
<td>spring.cloud.consul.retry.initial-interval</td>
<td>1000</td>
<td>初始重试间隔（以毫秒为单位）。</td>
</tr>
<tr>
<td>spring.cloud.consul.retry.max-attempts</td>
<td>6</td>
<td>最大尝试次数。</td>
</tr>
<tr>
<td>spring.cloud.consul.retry.max-interval</td>
<td>2000</td>
<td>退避的最大间隔</td>
</tr>
<tr>
<td>spring.cloud.consul.retry.multiplier</td>
<td>1.1</td>
<td>下一个间隔的乘数。</td>
</tr>
</tbody></table>
<h2 id="9-4-Config"><a href="#9-4-Config" class="headerlink" title="9.4 Config"></a>9.4 Config</h2><table>
<thead>
<tr>
<th>属性名</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>spring.cloud.config.allow-override</td>
<td>TRUE</td>
<td>标记以指示可以使用{@link  #isSystemPropertiesOverride（）systemPropertiesOverride}。设置为false以防止用户意外更改默认值。默认值为true。</td>
</tr>
<tr>
<td>spring.cloud.config.authorization</td>
<td></td>
<td>客户端使用的授权令牌连接到服务器。</td>
</tr>
<tr>
<td>spring.cloud.config.discovery.enabled</td>
<td>FALSE</td>
<td>标记以指示启用配置服务器发现（配置服务器URL将通过发现查找）。</td>
</tr>
<tr>
<td>spring.cloud.config.discovery.service-id</td>
<td>configserver</td>
<td>服务ID来定位配置服务器。</td>
</tr>
<tr>
<td>spring.cloud.config.enabled</td>
<td>TRUE</td>
<td>标记说远程配置启用。默认为true;</td>
</tr>
<tr>
<td>spring.cloud.config.fail-fast</td>
<td>FALSE</td>
<td>标记表示无法连接到服务器是致命的（默认为false）。</td>
</tr>
<tr>
<td>spring.cloud.config.label</td>
<td></td>
<td>用于拉取远程配置属性的标签名称。默认设置在服务器上（通常是基于git的服务器的“主”）。</td>
</tr>
<tr>
<td>spring.cloud.config.name</td>
<td></td>
<td>用于获取远程属性的应用程序名称。</td>
</tr>
<tr>
<td>spring.cloud.config.override-none</td>
<td>FALSE</td>
<td>标志表示当{@link  #setAllowOverride（boolean）allowOverride}为true时，外部属性应该采用最低优先级，并且不覆盖任何现有的属性源（包括本地配置文件）。默认为false。</td>
</tr>
<tr>
<td>spring.cloud.config.override-system-properties</td>
<td>TRUE</td>
<td>标记以指示外部属性应覆盖系统属性。默认值为true。</td>
</tr>
<tr>
<td>spring.cloud.config.password</td>
<td></td>
<td>联系远程服务器时使用的密码（HTTP Basic）。</td>
</tr>
<tr>
<td>spring.cloud.config.profile</td>
<td>default</td>
<td>获取远程配置时使用的默认配置文件（逗号分隔）。默认为“默认”。</td>
</tr>
<tr>
<td>spring.cloud.config.retry.initial-interval</td>
<td>1000</td>
<td>初始重试间隔（以毫秒为单位）。</td>
</tr>
<tr>
<td>spring.cloud.config.retry.max-attempts</td>
<td>6</td>
<td>最大尝试次数。</td>
</tr>
<tr>
<td>spring.cloud.config.retry.max-interval</td>
<td>2000</td>
<td>退避的最大间隔</td>
</tr>
<tr>
<td>spring.cloud.config.retry.multiplier</td>
<td>1.1</td>
<td>下一个间隔的乘数。</td>
</tr>
<tr>
<td>spring.cloud.config.server.bootstrap</td>
<td>FALSE</td>
<td>表示配置服务器应使用远程存储库中的属性初始化其自己的环境。默认情况下关闭，因为它会延迟启动，但在将服务器嵌入到另一个应用程序中时很有用。</td>
</tr>
<tr>
<td>spring.cloud.config.server.default-application-name</td>
<td>application</td>
<td>传入请求没有特定的默认应用程序名称。</td>
</tr>
<tr>
<td>spring.cloud.config.server.default-label</td>
<td></td>
<td>传入请求没有特定标签时的默认存储库标签。</td>
</tr>
<tr>
<td>spring.cloud.config.server.default-profile</td>
<td>default</td>
<td>传入请求没有特定的默认应用程序配置文件时。</td>
</tr>
<tr>
<td>spring.cloud.config.server.encrypt.enabled</td>
<td>TRUE</td>
<td>在发送给客户端之前启用对环境属性的解密。</td>
</tr>
<tr>
<td>spring.cloud.config.server.git.basedir</td>
<td></td>
<td>库的本地工作副本的基本目录。</td>
</tr>
<tr>
<td>spring.cloud.config.server.git.clone-on-start</td>
<td></td>
<td>标记以表明应该在启动时克隆存储库（不是按需）。通常会导致启动速度较慢，但第一次查询更快。</td>
</tr>
<tr>
<td>spring.cloud.config.server.git.default-label</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.config.server.git.environment</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.config.server.git.force-pull</td>
<td></td>
<td>标记表示存储库应该强制拉。如果真的丢弃任何本地更改并从远程存储库获取。</td>
</tr>
<tr>
<td>spring.cloud.config.server.git.git-factory</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.config.server.git.password</td>
<td></td>
<td>使用远程存储库验证密码。</td>
</tr>
<tr>
<td>spring.cloud.config.server.git.repos</td>
<td></td>
<td>存储库标识符映射到位置和其他属性。</td>
</tr>
<tr>
<td>spring.cloud.config.server.git.search-paths</td>
<td></td>
<td>在本地工作副本中使用的搜索路径。默认情况下只搜索根。</td>
</tr>
<tr>
<td>spring.cloud.config.server.git.timeout</td>
<td></td>
<td>用于获取HTTP或SSH连接的超时（以秒为单位）（如果适用）。默认5秒。</td>
</tr>
<tr>
<td>spring.cloud.config.server.git.uri</td>
<td></td>
<td>远程存储库的URI。</td>
</tr>
<tr>
<td>spring.cloud.config.server.git.username</td>
<td></td>
<td>用于远程存储库的身份验证用户名。</td>
</tr>
<tr>
<td>spring.cloud.config.server.health.repositories</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.config.server.native.fail-on-error</td>
<td>FALSE</td>
<td>标识以确定在解密期间如何处理异常（默认为false）。</td>
</tr>
<tr>
<td>spring.cloud.config.server.native.search-locations</td>
<td>[]</td>
<td>搜索配置文件的位置。默认与Spring Boot应用程序相同，因此[classpath：/，classpath：/ config  /，file：./，file：./ config /]。</td>
</tr>
<tr>
<td>spring.cloud.config.server.native.version</td>
<td></td>
<td>为本地存储库报告的版本字符串</td>
</tr>
<tr>
<td>spring.cloud.config.server.overrides</td>
<td></td>
<td>无条件发送给所有客户的资源的额外地图。</td>
</tr>
<tr>
<td>spring.cloud.config.server.prefix</td>
<td></td>
<td>配置资源路径的前缀（默认为空）。当您不想更改上下文路径或servlet路径时嵌入其他应用程序时很有用。</td>
</tr>
<tr>
<td>spring.cloud.config.server.strip-document-from-yaml</td>
<td>TRUE</td>
<td>标记为指示作为文本或集合（而不是映射）的YAML文档应以“本机”形式返回。</td>
</tr>
<tr>
<td>spring.cloud.config.server.svn.basedir</td>
<td></td>
<td>库的本地工作副本的基本目录。</td>
</tr>
<tr>
<td>spring.cloud.config.server.svn.default-label</td>
<td>trunk</td>
<td>用于环境属性请求的默认标签。</td>
</tr>
<tr>
<td>spring.cloud.config.server.svn.environment</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.config.server.svn.password</td>
<td></td>
<td>使用远程存储库验证密码。</td>
</tr>
<tr>
<td>spring.cloud.config.server.svn.search-paths</td>
<td></td>
<td>在本地工作副本中使用的搜索路径。默认情况下只搜索根。</td>
</tr>
<tr>
<td>spring.cloud.config.server.svn.uri</td>
<td></td>
<td>远程存储库的URI。</td>
</tr>
<tr>
<td>spring.cloud.config.server.svn.username</td>
<td></td>
<td>用于远程存储库的身份验证用户名。</td>
</tr>
<tr>
<td>spring.cloud.config.token</td>
<td></td>
<td>安全令牌通过到底层环境库。</td>
</tr>
<tr>
<td>spring.cloud.config.uri</td>
<td><a href="http://localhost:8888" target="_blank" rel="noopener">http://localhost:8888</a></td>
<td>远程服务器的URI（默认http：// localhost：8888）。</td>
</tr>
<tr>
<td>spring.cloud.config.username</td>
<td></td>
<td>联系远程服务器时使用的用户名（HTTP Basic）。</td>
</tr>
<tr>
<td>spring.cloud.consul.config.acl-token</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.config.data-key</td>
<td>data</td>
<td>如果格式为Format.PROPERTIES或Format.YAML，则使用以下字段来查找协调配置。</td>
</tr>
<tr>
<td>spring.cloud.consul.config.default-context</td>
<td>application</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.config.enabled</td>
<td>TRUE</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.config.fail-fast</td>
<td>TRUE</td>
<td>在配置查找期间抛出异常，如果为true，否则为日志警告。</td>
</tr>
<tr>
<td>spring.cloud.consul.config.format</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.config.prefix</td>
<td>config</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.config.profile-separator</td>
<td>,</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.consul.config.watch.delay</td>
<td>1000</td>
<td>手表的固定延迟的价值在毫秒。默认为1000。</td>
</tr>
<tr>
<td>spring.cloud.consul.config.watch.enabled</td>
<td>TRUE</td>
<td>如果手表启用 默认为true。</td>
</tr>
<tr>
<td>spring.cloud.consul.config.watch.wait-time</td>
<td>55</td>
<td>等待（或阻止）观看查询的秒数，默认为55.需要小于默认的ConsulClient（默认为60）。要增加ConsulClient超时，使用自定义的HttpClient创建一个带有自定义ConsulRawClient的ConsulClient  bean。</td>
</tr>
</tbody></table>
<h2 id="9-5-Stream"><a href="#9-5-Stream" class="headerlink" title="9.5 Stream"></a>9.5 Stream</h2><table>
<thead>
<tr>
<th>属性名</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>spring.cloud.stream.binders</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.bindings</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.consul.binder.event-timeout</td>
<td>5</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.consumer-defaults</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.default-binder</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.dynamic-destinations</td>
<td>[]</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.ignore-unknown-properties</td>
<td>TRUE</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.instance-count</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.instance-index</td>
<td>0</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.producer-defaults</td>
<td></td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.rabbit.binder.admin-adresses</td>
<td>[]</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.rabbit.binder.compression-level</td>
<td>0</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.rabbit.binder.nodes</td>
<td>[]</td>
<td></td>
</tr>
<tr>
<td>spring.cloud.stream.rabbit.bindings</td>
<td></td>
<td></td>
</tr>
</tbody></table>
</body></html></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="mailto:undefined">Cying-承影</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="http://cyingk.github.io/2020/05/05/SpringCloud/">http://cyingk.github.io/2020/05/05/SpringCloud/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/JavaEE/">JavaEE</a></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/07/22/JVM-Theory/"><img class="prev-cover" src="https://gitee.com/CyingK/files/raw/master/images/JVM/JVM-logo.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">JVM-Theory</div></div></a></div><div class="next-post pull-right"><a href="/2020/04/08/Operating-System/"><img class="next-cover" src="http://narpro.top/img/os.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">Operating_System</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> Related Articles</span></div><div class="relatedPosts-list"><div><a href="/2020/08/06/Linux-And-Docker/" title="SpringCloud With Docker"><img class="cover" src="https://img-blog.csdnimg.cn/202008061653587.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-08-06</div><div class="title">SpringCloud With Docker</div></div></a></div><div><a href="/2020/04/05/SpringBoot/" title="SpringBoot"><img class="cover" src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4157804759,1050439081&fm=26&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-04-05</div><div class="title">SpringBoot</div></div></a></div><div><a href="/2020/02/20/Mybatis/" title="MyBatis"><img class="cover" src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=575314515,4268715674&fm=26&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-20</div><div class="title">MyBatis</div></div></a></div><div><a href="/2020/02/16/SpringMVC/" title="SpringMVC"><img class="cover" src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=790255512,3591398303&fm=26&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-16</div><div class="title">SpringMVC</div></div></a></div><div><a href="/2020/02/15/Hibernate/" title="Hibernate"><img class="cover" src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=607365457,3589909035&fm=26&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-15</div><div class="title">Hibernate</div></div></a></div><div><a href="/2020/02/01/Struts2/" title="Struts2"><img class="cover" src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2597327423,2034793762&fm=26&gp=0.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-01</div><div class="title">Struts2</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">1.</span> <span class="toc-text">
    SpringCloud
</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%9F%BA%E6%9C%AC%E7%90%86%E5%BF%B5"><span class="toc-number">2.</span> <span class="toc-text">一、基本理念</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-1-Microservices"><span class="toc-number">2.1.</span> <span class="toc-text">1.1 Microservices</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-1-What-is-Microservices"><span class="toc-number">2.1.1.</span> <span class="toc-text">1.1.1 What is Microservices</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-2-Why-Microservices"><span class="toc-number">2.1.2.</span> <span class="toc-text">1.1.2 Why Microservices</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-2-SpringCloud"><span class="toc-number">2.2.</span> <span class="toc-text">1.2 SpringCloud</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-1-What-is-SpringCloud"><span class="toc-number">2.2.1.</span> <span class="toc-text">1.2.1 What is SpringCloud</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-2-Why-SpringCloud"><span class="toc-number">2.2.2.</span> <span class="toc-text">1.2.2 Why SpringCloud</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E6%9C%8D%E5%8A%A1%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83"><span class="toc-number">3.</span> <span class="toc-text">二、服务注册中心</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#2-1-Eureka"><span class="toc-number">3.1.</span> <span class="toc-text">2.1 Eureka</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-1-What-is-Eureka"><span class="toc-number">3.1.1.</span> <span class="toc-text">2.1.1 What is Eureka</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-2-Dependency"><span class="toc-number">3.1.2.</span> <span class="toc-text">2.1.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-3-Use"><span class="toc-number">3.1.3.</span> <span class="toc-text">2.1.3 Use</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-2-Zookeeper"><span class="toc-number">3.2.</span> <span class="toc-text">2.2 Zookeeper</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-1-What-is-Zookeeper"><span class="toc-number">3.2.1.</span> <span class="toc-text">2.2.1 What is Zookeeper</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-2-Dependency"><span class="toc-number">3.2.2.</span> <span class="toc-text">2.2.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-3-Use"><span class="toc-number">3.2.3.</span> <span class="toc-text">2.2.3 Use</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-3-Consul"><span class="toc-number">3.3.</span> <span class="toc-text">2.3 Consul</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-1-What-is-Consul"><span class="toc-number">3.3.1.</span> <span class="toc-text">2.3.1 What is Consul</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-2-Dependency"><span class="toc-number">3.3.2.</span> <span class="toc-text">2.3.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-3-Use"><span class="toc-number">3.3.3.</span> <span class="toc-text">2.3.3 Use</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%9C%8D%E5%8A%A1%E8%B0%83%E7%94%A8"><span class="toc-number">4.</span> <span class="toc-text">三、服务调用</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-1-Ribbon"><span class="toc-number">4.1.</span> <span class="toc-text">3.1 Ribbon</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-1-What-is-Ribbon"><span class="toc-number">4.1.1.</span> <span class="toc-text">3.1.1 What is Ribbon</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-2-Dependency"><span class="toc-number">4.1.2.</span> <span class="toc-text">3.1.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-3-Use"><span class="toc-number">4.1.3.</span> <span class="toc-text">3.1.3 Use</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-2-OpenFeign"><span class="toc-number">4.2.</span> <span class="toc-text">3.2 OpenFeign</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-1-What-is-OpenFeign"><span class="toc-number">4.2.1.</span> <span class="toc-text">3.2.1 What is OpenFeign</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-2-Dependency"><span class="toc-number">4.2.2.</span> <span class="toc-text">3.2.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-3-Use"><span class="toc-number">4.2.3.</span> <span class="toc-text">3.2.3 Use</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E6%9C%8D%E5%8A%A1%E6%96%AD%E8%B7%AF%E5%99%A8"><span class="toc-number">5.</span> <span class="toc-text">四、服务断路器</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#4-1-Hystrix"><span class="toc-number">5.1.</span> <span class="toc-text">4.1 Hystrix</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-1-What-is-Hystrix"><span class="toc-number">5.1.1.</span> <span class="toc-text">4.1.1 What is Hystrix</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-2-Dependency"><span class="toc-number">5.1.2.</span> <span class="toc-text">4.1.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-3-Use"><span class="toc-number">5.1.3.</span> <span class="toc-text">4.1.3 Use</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#4-1-3-1-fallback"><span class="toc-number">5.1.3.1.</span> <span class="toc-text">4.1.3.1 fallback</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#4-1-3-1-1-%E7%94%A8%E4%BA%8E%E6%9C%8D%E5%8A%A1%E7%AB%AF"><span class="toc-number">5.1.3.1.1.</span> <span class="toc-text">4.1.3.1.1 用于服务端</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-1-3-1-2-%E7%94%A8%E4%BA%8E%E5%AE%A2%E6%88%B7%E7%AB%AF"><span class="toc-number">5.1.3.1.2.</span> <span class="toc-text">4.1.3.1.2 用于客户端</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-1-3-1-3-%E5%85%A8%E5%B1%80%E9%99%8D%E7%BA%A7%E6%96%B9%E6%B3%95"><span class="toc-number">5.1.3.1.3.</span> <span class="toc-text">4.1.3.1.3 全局降级方法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-1-3-1-4-%E7%BB%93%E5%90%88-OpenFeign"><span class="toc-number">5.1.3.1.4.</span> <span class="toc-text">4.1.3.1.4 结合 OpenFeign</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-1-3-2-CirecuitBreaker"><span class="toc-number">5.1.3.2.</span> <span class="toc-text">4.1.3.2 CirecuitBreaker</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-4-Hystrix-Dashboard"><span class="toc-number">5.1.4.</span> <span class="toc-text">4.1.4 Hystrix Dashboard</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%94%E3%80%81%E6%9C%8D%E5%8A%A1%E7%BD%91%E5%85%B3"><span class="toc-number">6.</span> <span class="toc-text">五、服务网关</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#5-1-Gateway"><span class="toc-number">6.1.</span> <span class="toc-text">5.1 Gateway</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1-1-What-is-Gateway"><span class="toc-number">6.1.1.</span> <span class="toc-text">5.1.1 What is Gateway</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1-2-Dependency"><span class="toc-number">6.1.2.</span> <span class="toc-text">5.1.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1-3-Use"><span class="toc-number">6.1.3.</span> <span class="toc-text">5.1.3 Use</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#5-1-3-1-Route-amp-Predicate"><span class="toc-number">6.1.3.1.</span> <span class="toc-text">5.1.3.1 Route &amp; Predicate</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-1-3-2-Filter"><span class="toc-number">6.1.3.2.</span> <span class="toc-text">5.1.3.2 Filter</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-1-3-3-CORS"><span class="toc-number">6.1.3.3.</span> <span class="toc-text">5.1.3.3.CORS</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%AD%E3%80%81%E6%9C%8D%E5%8A%A1%E9%85%8D%E7%BD%AE"><span class="toc-number">7.</span> <span class="toc-text">六、服务配置</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#6-1-Config"><span class="toc-number">7.1.</span> <span class="toc-text">6.1 Config</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#6-1-1-What-is-Config"><span class="toc-number">7.1.1.</span> <span class="toc-text">6.1.1 What is Config</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-1-2-Dependency"><span class="toc-number">7.1.2.</span> <span class="toc-text">6.1.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-1-3-Use"><span class="toc-number">7.1.3.</span> <span class="toc-text">6.1.3 Use</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%83%E3%80%81%E6%9C%8D%E5%8A%A1%E6%80%BB%E7%BA%BF"><span class="toc-number">8.</span> <span class="toc-text">七、服务总线</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#7-1-Bus"><span class="toc-number">8.1.</span> <span class="toc-text">7.1 Bus</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#7-1-1-What-is-Bus"><span class="toc-number">8.1.1.</span> <span class="toc-text">7.1.1 What is Bus</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-1-2-Dependency"><span class="toc-number">8.1.2.</span> <span class="toc-text">7.1.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-1-3-Use"><span class="toc-number">8.1.3.</span> <span class="toc-text">7.1.3 Use</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-2-Stream"><span class="toc-number">8.2.</span> <span class="toc-text">7.2 Stream</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#7-2-1-What-is-Stream"><span class="toc-number">8.2.1.</span> <span class="toc-text">7.2.1 What is Stream</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-2-2-Dependency"><span class="toc-number">8.2.2.</span> <span class="toc-text">7.2.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-2-3-Use"><span class="toc-number">8.2.3.</span> <span class="toc-text">7.2.3 Use</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%AB%E3%80%81SpringCloud-Alibaba"><span class="toc-number">9.</span> <span class="toc-text">八、SpringCloud Alibaba</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#8-1-Nacos"><span class="toc-number">9.1.</span> <span class="toc-text">8.1 Nacos</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#8-1-1-What-is-Nacos"><span class="toc-number">9.1.1.</span> <span class="toc-text">8.1.1 What is Nacos</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-1-2-Dependency"><span class="toc-number">9.1.2.</span> <span class="toc-text">8.1.2 Dependency</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-1-3-Use"><span class="toc-number">9.1.3.</span> <span class="toc-text">8.1.3 Use</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#8-1-3-1-%E6%9C%8D%E5%8A%A1%E6%B3%A8%E5%86%8C"><span class="toc-number">9.1.3.1.</span> <span class="toc-text">8.1.3.1 服务注册</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-1-3-2-%E6%9C%8D%E5%8A%A1%E9%85%8D%E7%BD%AE"><span class="toc-number">9.1.3.2.</span> <span class="toc-text">8.1.3.2 服务配置</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-2-3-Use"><span class="toc-number">9.1.4.</span> <span class="toc-text">8.2.3 Use</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#8-2-3-1-%E6%B5%81%E9%87%8F%E6%8E%A7%E5%88%B6"><span class="toc-number">9.1.4.1.</span> <span class="toc-text">8.2.3.1 流量控制</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#8-2-3-1-1-QPS-%E7%9B%B4%E6%8E%A5-%E5%BF%AB%E9%80%9F%E5%A4%B1%E8%B4%A5"><span class="toc-number">9.1.4.1.1.</span> <span class="toc-text">8.2.3.1.1 QPS-直接-快速失败</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#8-2-3-1-2-%E7%BA%BF%E7%A8%8B%E6%95%B0-%E7%9B%B4%E6%8E%A5-%E5%BF%AB%E9%80%9F%E5%A4%B1%E8%B4%A5"><span class="toc-number">9.1.4.1.2.</span> <span class="toc-text">8.2.3.1.2 线程数-直接-快速失败</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#8-2-3-1-3-QPS-%E5%85%B3%E8%81%94-%E5%BF%AB%E9%80%9F%E5%A4%B1%E8%B4%A5"><span class="toc-number">9.1.4.1.3.</span> <span class="toc-text">8.2.3.1.3 QPS-关联-快速失败</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#8-2-3-1-4-QPS-%E7%9B%B4%E6%8E%A5-warm-up"><span class="toc-number">9.1.4.1.4.</span> <span class="toc-text">8.2.3.1.4  QPS-直接-warm up</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#8-2-3-1-5-QPS-%E7%9B%B4%E6%8E%A5-%E6%8E%92%E9%98%9F%E7%AD%89%E5%BE%85"><span class="toc-number">9.1.4.1.5.</span> <span class="toc-text">8.2.3.1.5 QPS-直接-排队等待</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-2-3-2-%E7%86%94%E6%96%AD%E9%99%8D%E7%BA%A7"><span class="toc-number">9.1.4.2.</span> <span class="toc-text">8.2.3.2 熔断降级</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#8-2-3-2-1-RT"><span class="toc-number">9.1.4.2.1.</span> <span class="toc-text">8.2.3.2.1 RT</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#8-2-3-2-2-%E5%BC%82%E5%B8%B8%E6%AF%94%E4%BE%8B"><span class="toc-number">9.1.4.2.2.</span> <span class="toc-text">8.2.3.2.2 异常比例</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#8-2-3-2-3-%E5%BC%82%E5%B8%B8%E6%95%B0"><span class="toc-number">9.1.4.2.3.</span> <span class="toc-text">8.2.3.2.3 异常数</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-2-3-3-%E7%83%AD%E7%82%B9"><span class="toc-number">9.1.4.3.</span> <span class="toc-text">8.2.3.3 热点</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-2-3-4-SentinelResource"><span class="toc-number">9.1.4.4.</span> <span class="toc-text">8.2.3.4 @SentinelResource</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#8-2-3-4-1-%E5%B1%80%E9%83%A8"><span class="toc-number">9.1.4.4.1.</span> <span class="toc-text">8.2.3.4.1 局部</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#8-2-3-4-2-%E5%85%A8%E5%B1%80"><span class="toc-number">9.1.4.4.2.</span> <span class="toc-text">8.2.3.4.2 全局</span></a></li></ol></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B9%9D%E3%80%81%E9%99%84%E5%BD%95"><span class="toc-number">10.</span> <span class="toc-text">九、附录</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#9-1-Eureka-Properties"><span class="toc-number">10.1.</span> <span class="toc-text">9.1 Eureka Properties</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#9-1-1-instance"><span class="toc-number">10.1.1.</span> <span class="toc-text">9.1.1 instance</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-1-2-server"><span class="toc-number">10.1.2.</span> <span class="toc-text">9.1.2 server</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-1-3-client"><span class="toc-number">10.1.3.</span> <span class="toc-text">9.1.3 client</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9-2-Zookeeper"><span class="toc-number">10.2.</span> <span class="toc-text">9.2 Zookeeper</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9-3-Consul"><span class="toc-number">10.3.</span> <span class="toc-text">9.3 Consul</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9-4-Config"><span class="toc-number">10.4.</span> <span class="toc-text">9.4 Config</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9-5-Stream"><span class="toc-number">10.5.</span> <span class="toc-text">9.5 Stream</span></a></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="footer_custom_text">却道天凉好个秋</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="Increase font size"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="Decrease font size"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (document.getElementsByClassName('mermaid').length) {
  if (window.mermaidJsLoad) mermaid.init()
  else {
    getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(() => {
      window.mermaidJsLoad = true
      mermaid.initialize({
        theme: 'default',
      })
      false && mermaid.init()
    })
  }
}</script></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>